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('note_id')) { $note_id = $this->request->get('note_id'); $model = $model->where('note_id', '=', $note_id); } if ($this->request->filled('parent_id')) { $parent_id = $this->request->get('parent_id'); $model = $model->where('parent_id', '=', $parent_id); } if ($this->request->filled('id')) { $id = $this->request->get('id'); $model = $model->where('id', '=', $id); } $model = $model->orderByDesc('is_answer')->orderByDesc('id'); return $model; } }