groups
表格中username
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);
欢迎任何帮助......
答案 0 :(得分:0)
认为它应该是这样的:
Groups::with('User')->whereHas('User', function($q) use ($key){
$q->where('username', 'like', '%'.$key.'%');
})->where('status', 1)->paginate($pagVal);