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('account')) { $account = $this->request->get('account'); $model = $model->where('account', 'like', "%{$account}"); } if ($this->request->filled('garde_id')) { $garde_id = $this->request->get('garde_id'); $model = $model->where('garde_id', $garde_id); } if ($this->request->filled('garde_ids')) { $garde_ids = $this->request->get('garde_ids'); $model = $model->whereIn('garde_id', $garde_ids); } if ($this->request->filled('ids')) { $ids = $this->request->get('ids'); $model = $model->whereIn('id', $ids); } 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('orderBy')) { $model = $model->orderByDesc('id'); } return $model; } }