The way I did this is querying a model Postwith a relation whereDoesnthave. In the controller:
public function getPostsWithoutCommenter(){
$userId = 1;
$posts = \App\Post::whereDoesntHave("comments", function($subQuery) use($userId){
$subQuery->where("user_id", "=", $userId);
})->get();
}
This suggests that it commentsis defined in the model Postas follows:
public function comments(){
return $this->hasMany(Comment::class);
}
, comments $userId a Collection, .