user = $user; $this->search = $search; } public function apply(Builder $builder, Model $model) { if(empty($this->search['top_depart_id'])){ //默认进来 只显示自己公司下的 自己权限范围下的部门数据 $top_depart_id = $this->user['depart_top'][0] ?? []; $top_depart_id = $top_depart_id['depart_id'] ?? 0; }else{ //查询给的公司下的 自己权限范围下的部门数据 $top_depart_id = $this->search['top_depart_id']; } $builder->where('top_depart_id', $top_depart_id) ->whereIn('depart_id', $this->user['depart_range']); } }