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', false)) { $status = $this->request->get('status'); $model = $model->where('status', '=', $status); } else { $model = $model->where('status', '=', ModelStatusEnum::OK); } if ($this->request->filled('course_id')) { $course_id = $this->request->get('course_id'); $model = $model->where('course_id', '=', $course_id); } if ($this->request->filled('video_id')) { $video_id = $this->request->get('video_id'); $model = $model->where('course_video_id', '=', $video_id); } $model = $model->orderByDesc('sort')->orderBy('id'); return $model; } }