hootlex / laravel-friendships

This package gives Eloquent models the ability to manage their friendships.
MIT License
703 stars 151 forks source link

How to handle User when model extends Authenticatable instead of Model #105

Closed jake5253 closed 6 years ago

jake5253 commented 6 years ago

As per the title, my Users model extends Authenticatable not Model.

I got $user->befriend($id) and $user->getPendingFriendship() to work by calling $user = \Auth::user(); but the same does not work for $user->acceptFriendRequest(): Type error: Argument 1 passed to App\User::acceptFriendRequest() must be an instance of Illuminate\Database\Eloquent\Model, string given, called in /home/vagrant/code/neighbor/app/Http/Controllers/FriendController.php on line 29

I assume this is because of my model extending the wrong thing, but I dont think I can change it to extend Model without rewriting a large portion of my app? Can I just change my model to extend Model and then implement all the auth?

UPDATE: I guess I figured that original problem out. I was passing just the user ID and not the model. Changed code as follows. Now I get Method Illuminate\Database\Eloquent\Collection::acceptFriendRequest does not exist.

    public function acceptRequest($id)
    {
        $user = User::find(auth()->user());
        $requestee = User::find($id)->first();
        return $user->acceptFriendRequest($requestee);
    }

UPDATE AGAIN: Got it! needed to set $user (above) as \Auth::user()

Thank you.

agamyrat301 commented 5 years ago

that was what I was looking for