我有以下Eloquent 的模型:
User | id
Post | id
Comment | id | post | id |用户| id
使用eloquent,如何获取特定用户尚未发表 comments 的所有帖子?
到目前为止我试过:
在型号Post中:
public function noCommentOf(User $user) {
$this->hasNot('App\Comment')->commentOf($user);
}
在型号Comment中:
public function commentOf($query, User $user) {
return $query->where('user_id', '=', $user->id);
}