I've a Post model and a Like model. When I go a user page, I can see all the posts he liked. And now I want to indicate a small icon is it's already liked by the logged user who's visiting a user page.
This is how I select the likes posts of the user. (not the logged user but the profile owner).
$likesPost = Post::with('user')->join('likes', function($join) use ($user){
$join->on('likes.likeable_id', '=', 'id')->where('likes.user_id', '=', $user->id)->where('likes.likeable_type','=', Post::class);
})->get();
Now I want to also check if the authenticated user has already liked this post or not along with this query. I've tried many things but I'm not sure how I should approach this problem. I'm using Polymorphic relation .
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire