request = $request; } /** * @param $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('name')) { $val = $this->request->get('name'); $model = $model->where('name', 'like', "%{$val}%"); } if ($this->request->filled('status')) { $status = $this->request->get('status'); $model = $model->where('status', '=', $status); } if ($this->request->filled('ids')) { $ids = $this->request->get('ids'); $model = $model->whereIn('id', $ids); } if (!$this->request->filled('orderBy')) { $model = $model->orderByDesc('id'); } return $model; } }