我无法使用预先负载约束根据表中username
过滤groups
表的内容users
public function username()
{
return $this->belongsTo('User','fk_users_id')->select(['id','username']);
}
我尝试使用以下代码,但它仅过滤users
数据而不是groups
数据
$groups = Groups::with(array('username' => function($query) use ($keyword)
{
$query->where('username', 'like', '%'.$keyword.'%');
}))
->where('status',1)->paginate($paginateValue);
欢迎任何帮助...
认为它应该是这样的:
Groups::with('User')->whereHas('User', function($q) use ($key){
$q->where('username', 'like', '%'.$key.'%');
})->where('status', 1)->paginate($pagVal);