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 ($name = $this->request->get('name')) { $model = $model->where('name', 'like', "%{$name}%"); } if ($key = $this->request->get('key')) { $model = $model->where('key', 'like', "%{$key}%"); } if ($keys = $this->request->get('keys')) { $model = $model->whereIn('key', str2arr($keys)); } if (($status = $this->request->get('status', false)) !== false && !is_null($status)) { $model = $model->where('status', '=', $status); } if ($id = $this->request->get('id')) { $model = $model->where('id', '=', $id); } $model = $model->orderByDesc('sort')->orderByDesc('id'); return $model; } }