直接添加一個where條件,然后條件里面用表名.字段即可,非常方便
需要注意的一點是在fastadmin里面,$this->auth->getGroupIds()這樣獲取是會獲取到緩存里面的值,必須重新登錄之后才可以得到最新的用戶組,這個問題導致困擾了我一晚上
$usage = $this->model->with(['user', 'device', 'devicetype']);if (in_array(3, $this->auth->getGroupIds()) || in_array(5, $this->auth->getGroupIds())) {//用戶角色為業務員或者銷售經理時,只顯示所在區域的設備$usage->where('user.area_id', 'in', $this->auth->area_ids);}$list = $usage->where($where)->order($sort, $order)->paginate($limit);