request = $request; } /** * @param $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('day')) { $val = $this->request->get('day'); if (is_string($val)) $model = $model->where('day', '=', $val); if (is_array($val)) { $model = $model->where('day', '>=', $val[0])->where('day', '<=', $val[1]); } } if ($this->request->filled('day_type')) { $val = $this->request->get('day_type'); $model = $model->where('day_type', '=', $val); } if ($this->request->filled('type')) { $val = $this->request->get('type'); $model = $model->where('type', '=', $val); } if ($this->request->filled('group_id')) { $val = $this->request->get('group_id'); $model = $model->where('group_id', '=', $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; } }