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('username')) { $model = $model->where('username', 'like', '%' . $this->request->get('username') . '%'); } if ($this->request->filled('mobile')) { $model = $model->where('mobile', 'like', '%' . $this->request->get('mobile') . '%'); } if ($this->request->filled('email')) { $model = $model->where('email', 'like', '%' . $this->request->get('email') . '%'); } if ($this->request->filled('sex')) { $model = $model->where('sex', '=', $this->request->get('sex')); } if ($this->request->filled('department_id')) { $model = $model->where('department_id', '=', $this->request->get('department_id')); } if ($this->request->filled('status')) { $model = $model->where('status', '=', $this->request->get('status')); } if ($this->request->filled('type')) { $model = $model->where('type', '=', $this->request->get('type')); } if ($this->request->filled('company_id')) { $model = $model->where('company_id', '=', $this->request->get('company_id')); } if ($this->request->filled('role_name')) { $role_name = $this->request->get('role_name'); $model = $model->whereHas('roles', function ($query) use ($role_name) { return $query->where('name', $role_name); }); } if ($this->request->filled('role_id')) { $role_id = $this->request->get('role_id'); $model = $model->whereHas('roles', function ($query) use ($role_id) { return $query->where('id', $role_id); }); } 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('orderBy')) { $model = $model->orderBy('id'); } $model = $model->where('type', '=', AdminTypeEnum::ADMIN); return $model; } }