我需要查询数据透视表project_user以获取done = 1的列,以及project_user中存在的项目ID。 ?如何在Eloquent中使用它?
提前谢谢。
projects
-id
-user_id
users
-id
project_users
-user_id
-project_id
-done
class Projec extends Model{
public function users(){
return $this->belongsToMany(User::class)->withPivot('done');
}
}
class User extends Model{
public function projects(){
return $this->belongsToMany(Project::class)->withPivot('done');
}
}
答案 0 :(得分:0)
试试这个:
User::find($id)->projects()->wherePivot('done', 1)->get();