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('name')) { $name = $this->request->get('name'); $model = $model->where('name', 'like', "%{$name}%"); } if ($this->request->filled('status')) { $status = $this->request->get('status'); $model = $model->where('status', '=', $status); } else { $model = $model->where('status', '=', ModelStatusEnum::OK); } if ($this->request->filled('project_id')) { $project_id = $this->request->get('project_id', false); $model = $model->where('project_id', '=', $project_id); } if ($this->request->filled('type')) { $type = $this->request->get('type', false); $model = $model->where('type', '=', $type); } if (is_admin_login()) { $admin = login_admin(); if ($admin->role_id > RoleEnum::ADMIN) { $model = $model->where('shop_id', $admin->shop_id); } } $model = $model->orderByDesc('id'); return $model; } }