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 ($title = $this->request->get('title')) { $model = $model->where('name', 'like', "%{$title}%"); } if ($course_category_id = $this->request->get('course_category_id')) { $model = $model->where('course_category_id', '=', $course_category_id); } if ($tags = $this->request->get('tags')) { $model = $model->where('tags', 'like', "%-{$tags}-%"); } if (($status = $this->request->get('status', false)) !== false) { $model = $model->where('status', '=', $status); } if ($id = $this->request->get('id')) { $model = $model->where('id', '=', $id); } if (($is_release = $this->request->get('is_release', false)) !== false) { $model = $model->where('is_release', '=', $is_release); } if (($type = $this->request->get('type', false)) !== false) { $model = $model->where('type', '=', $type); } if ($this->request->get('me')) { $model = $model->where('user_id', login_user_id()); } if ($tag = $this->request->get('tag')) { switch ($tag) { case 'new': $model = $model->orderByDesc('id'); break; case 'hot': $model = $model->orderByDesc('good_count')->orderByDesc('id'); break; } } else { $model = $model->orderByDesc('id'); } return $model; } }