GithubHelp home page GithubHelp logo

Comments (13)

hootlex avatar hootlex commented on May 14, 2024

Hello Robin,
It should work this way. I will check it out.

from laravel-friendships.

hootlex avatar hootlex commented on May 14, 2024

As I can see this is the default behaviour of a Friendship.

For example:

$sender = createUser();
$recipient = createUser();

$sender->befriend($recipient);
$recipient->acceptFriendRequest($sender);

//Result
$recipient->isFriendWith($sender); //true
$sender->isFriendWith($recipient); //true

Now $sender->getAcceptedFriendships() returns

Illuminate\Database\Eloquent\Collection {#982
     all: [
       Hootlex\Friendships\Models\Friendship {#984
         id: 66,
         sender_id: 11,
         sender_type: "App\User",
         recipient_id: 12,
         recipient_type: "App\User",
         status: 1,
         created_at: "2016-01-15 01:46:18",
         updated_at: "2016-01-15 01:46:20",
       },
     ],
   }

And $recipiend->getAcceptedFriendships() returns the same

Illuminate\Database\Eloquent\Collection {#982
     all: [
       Hootlex\Friendships\Models\Friendship {#984
         id: 66,
         sender_id: 11,
         sender_type: "App\User",
         recipient_id: 12,
         recipient_type: "App\User",
         status: 1,
         created_at: "2016-01-15 01:46:18",
         updated_at: "2016-01-15 01:46:20",
       },
     ],
   }

from laravel-friendships.

RosiersRobin avatar RosiersRobin commented on May 14, 2024

So, how would I be able to display everything and check if the persons are already friends?

Also, I'm trying to use the package in this way:

User::find(Auth::id())->isFriendWith($userdata->UID) wich should be rendered something like this:
User::find(18)->isFriendWith(4).

But that gives me the following error:
Argument 1 passed to User::isFriendWith() must be an instance of Illuminate\Database\Eloquent\Model, integer given

Yes, I included the package in the user model:

use Hootlex\Friendships\Traits\Friendable;

class User extends Model implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
{
    use Authenticatable, CanResetPassword, HasRoleAndPermission, Friendable;
...

Can this be a issue? Or how should I handle the package (in my view)?

from laravel-friendships.

hootlex avatar hootlex commented on May 14, 2024

The isFriendWith expects a model as a parameter not an integer. In order to check if two users are friends you have to use it this way:

User::find(18)->isFriendWith(User::find(4))

from laravel-friendships.

hootlex avatar hootlex commented on May 14, 2024

I will implement a getFriends method which will return all User friends instead of returning Friendship objects.

from laravel-friendships.

RosiersRobin avatar RosiersRobin commented on May 14, 2024

It worked. Could you maybe also implement a function that checks if a user has a pending request of another user?

Something like

User::find(Auth::id())->isPendingFriend(User::find($userdata->UID))

The Auth returns the current user id and the $userdata->UID is the ID of the users profile i'm watching on.
This would be handy for me like if a users has a pending request, of user X, I can display a cancel button to cancel the request.

from laravel-friendships.

hootlex avatar hootlex commented on May 14, 2024

Checking friendship status between two users can be easily done via getFriendship().

example:

$friendship = $sender->getFriendship($recipient)
if($friendship->status == Status::PENDING){
    //your code
}

$friendship is an instance of Friendship.

Hootlex\Friendships\Models\Friendship {#962
     id: 333,
     sender_id: 441,
     sender_type: "App\User",
     recipient_id: 445,
     recipient_type: "App\User",
     status: 0,
     created_at: "2016-01-16 01:36:08",
     updated_at: "2016-01-16 01:36:08",
   }

from laravel-friendships.

RosiersRobin avatar RosiersRobin commented on May 14, 2024

I found something else (made some new code in your package).

But when I try to count how many friends someone has, it returns 1 already on the requested friend.

So Current friends: User A: 0 User B: 0.

When user B request a friendship to user A, User A has 1 friend (not accepted yet) and user B has 0 friends. Code that I'm using:

User::find($userdata->UID)->getAcceptedFriendships()->count()

I don't know how I can use it in any other way?

from laravel-friendships.

hootlex avatar hootlex commented on May 14, 2024

Maybe you are using an old version. This is fixed in v1.0.7.

Also I have added $user->getFriends() in v1.0.8!

from laravel-friendships.

RosiersRobin avatar RosiersRobin commented on May 14, 2024

Cool! Now this works like a charm! Thanks for adding my requested features! If you need any help, just give me a shout 😄

from laravel-friendships.

hootlex avatar hootlex commented on May 14, 2024

Thanks! :)

from laravel-friendships.

pkitatta avatar pkitatta commented on May 14, 2024

Hi, can this system avoid duplicate rows of relationship. Example - can sender_id, recipient - 3,2 be stored as 2,3, so that makes 2 records for the same relationship.

from laravel-friendships.

RosiersRobin avatar RosiersRobin commented on May 14, 2024

Well if one row already exists, then you'll have a "friendship". But if there are two rows like you say (wich you can avoid in your project) will not affect the output.

from laravel-friendships.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.