Laravel eloquant 'whereDoesntHave' get posts not only commented by one user

I need to get the posts, without the posts which only commented by specific user.

Relation in Post model,

public function comments(){
return $this->hasMany(Comment::class);
}

This is my code,

public function getPostsWithoutCommenter(){
$userId = 1;
$posts = \App\Post::whereDoesntHave("comments", function($subQuery) use($userId){
$subQuery->where("user_id", "=", $userId);
})->get();
}

This code omits 'Posts which a specific User has commented'. But I want to "omit posts Only that user commented". Which means if some other user also commented I want that in resulset. Is there an eloquant way to do this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3BYTwIS
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

How to Create Treeview with Bootstrap and jQuery

Api routes not found when hosted laravel application on server

How to Add Images to Dropdown List using jQuery