// 查詢用戶昵稱是think的用戶
// 注意第一個參數是關聯方法名(不是關聯模型名)
$users = User::hasWhere('profile', ['nickname'=>'think'])->select();
// 可以使用閉包查詢
$users = User::hasWhere('profile', function($query) {
$query->where('nickname', 'like', 'think%');
})->select();
模型里面
public function authGroupAccess()
{
return $this->belongsTo('authGroupAccess', 'id', 'uid')->bind('group_id');
}
控制器里面:
hasWhere的使用
if (!empty($param['group_id'])) {
$haswhere['group_id'] = $param['group_id'];
}
$list = model('admin')
->hasWhere('authGroupAccess', $haswhere)
->with('authGroupAccess,authGroup')
->where('username', 'neq', 'admin')
->order('id','desc')
->where($where)
->paginate(config('page_number'));
文章來源:劉俊濤的博客 歡迎關注公眾號、留言、評論,一起學習。
若有幫助到您,歡迎點擊推薦,您的支持是對我堅持最好的肯定(*^_^*)