request = $request; } /** * @param $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('type')) { $type = $this->request->get('type'); $model = $model->where('type', '=', $type); } if ($this->request->filled('name')) { $name = $this->request->get('name'); $model = $model->where('name', 'like', "%{$name}%"); } if ($this->request->filled('is_show')) { $time = Carbon::now()->toDateTimeString(); $model = $model->where('start_time', '<=', $time)->where('end_time', '>', $time)->where('status', '=', ModelStatusEnum::OK); } if ($this->request->filled('status')) { $status = $this->request->get('status'); $model = $model->where('status', '=', $status); } if (!$this->request->filled('orderBy')) { $model = $model->orderByDesc('sort')->orderByDesc('id'); } return $model; } }