request = $request; } /** * @param $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('name')) { $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%'); } if ($this->request->filled('user_no')) { $model = $model->where('user_no', 'like', '%' . $this->request->get('user_no')); } if ($this->request->filled('mobile')) { $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile')); } if ($this->request->filled('remark')) { $model = $model->where('remark', 'like', '%' . $this->request->get('remark') . '%'); } if ($this->request->filled('type')) { $model = $model->where('type', '=', $this->request->get('type')); } if ($this->request->filled('department_id')) { $model = $model->where('department_id', '=', $this->request->get('department_id')); } if ($this->request->filled('bike_nums')) { $bike_nums = $this->request->get('bike_nums'); $userIds = Bike::query()->select(DB::raw("user_id,count(id) as nums"))->groupBy('user_id')->having('nums', $bike_nums)->pluck('user_id'); $model = $model->whereIn('id', $userIds); } if ($this->request->filled('status')) { $model = $model->where('status', '=', $this->request->get('status')); } $model = $model->where('type', '>', AdminTypeEnum::ADMIN); return $model; } }