cybercog / laravel-love

Add Social Reactions to Laravel Eloquent Models. It lets people express how they feel about the content. Fully customizable Weighted Reaction System & Reaction Type System with Like, Dislike and any other custom emotion types. Do you react?

Home Page:https://komarev.com/sources/laravel-love

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

if I use JWT Auth as api auth and use Illuminate\Support\Facades\Auth as web auth,what to do ?

lvtu0316 opened this issue · comments

if I use jwt Auth as api auth and use Illuminate\Support\Facades\Auth as web auth,in my user model, what is Authenticatable ?

Hi, @lvtu0316!
This package doesn't depend on Authenticatable class in any way. Just make any model reacterable following to the Setup Reacterable documentation section. In example code block I provided Authenticatable because it's default User model from the first Laravel installation.

If you still have questions - please describe them in more detail.

The User Model is:

use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable implements JWTSubject, LikerContract
use Cog\Contracts\Love\Liker\Models\Liker as LikerContract;
use Cog\Laravel\Love\Liker\Models\Traits\Liker;
{
    use Liker;
}

The Api/TopicsController is:

// 点赞
    public function like(Topic $topic, User $user)
    {
        
        if ($user->hasLiked($topic))
        {
            $user->unlike($topic);
        }else{
            $user->like($topic);
        }

        $likers = $topic->collectLikers();

        return $this->response->array($likers);

    }

but

"message": "Type error: Return value of Cog\\Laravel\\Love\\Likeable\\Services\\LikeableService::getLikerUserId() must be of the type integer, null returned",`

I sloved by:

public function like(Topic $topic)
    {
        $user = \Auth::user();
        if ($user->hasLiked($topic))
        {
            $user->unlike($topic);
        }else{
            $user->like($topic);
        }

        $likers = $topic->collectLikers();

        return $this->response->array($likers);

    }

Ah... you are using very old version of the package. Old versions were tightly coupled with default Laravel application. If it's not on production yet, I highly recommend you to start integration from the scratch and take v8.1.2 as the basis. If you can't switch to the new version for some reason - tell me what exact version are you using.

I used v5.1, ok, I will upgrade to the latest version! Thanks .

I'm closing this issue. Feel free to open new issues if there will be another questions.