User Model
public function roles()
{
return $this->belongsToMany(Role);
}Role Model
public function users()
{
return $this->belongsToMany(User);
}Controller
'roles' => function ($query) use ($value) {
$query->where('role_id', $value);
}查询User表,关联Role 多对多关联查询时候,返回结果不是很理想啊查询User表,Role等于1的,应该返回User关联Role等于1的。
但是返回结果 Role=1返回了,但是User关联中Role!=1的也返回了...
不应该仅仅返回我查询的条件的嘛?
还有 belongsToMany 不支持hasWhere查询嘛?
最佳答案