request = \request(); } else { $this->request = $request; } } /** * Apply criteria in query repository * * @param string $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('turename')) { $turename = $this->request->get('turename'); $model = $model->where('turename', 'like', "%{$turename}%"); } if ($this->request->filled('username')) { $username = $this->request->get('username'); $model = $model->where('username', 'like', "%{$username}%"); } if ($this->request->filled('mobile')) { $mobile = $this->request->get('mobile'); $model = $model->where('mobile', 'like', "%{$mobile}%"); } if ($this->request->filled('class')) { $class = $this->request->get('class'); $model = $model->where('class', 'like', "%{$class}%"); } if ($this->request->filled('name')) { $name = $this->request->get('name'); $model = $model->where('name', 'like', "%{$name}%"); } if ($this->request->filled('sex')) { $sex = $this->request->get('sex'); $model = $model->where('sex', '=', $sex); } if ($this->request->filled('role_id')) { $role_id = $this->request->get('role_id'); $model = $model->where('role_id', '=', $role_id); } // if ($period = $this->request->get('period')) { // $model = $model->where('period', 'like', $period); // } if ($this->request->filled('organization_id')) { $organization_id = $this->request->get('organization_id'); $model = $model->whereHas('organizations', function ($query) use ($organization_id) { return $query->where('organization_id', $organization_id); }); } $model = $model->orderByDesc('id'); return $model; } }