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('user_mobile')) { $val = $this->request->get('user_mobile'); $ids = User::byMobileGetIds($val); $model = $model->whereIn('user_id', $ids); } 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('sort')->orderByDesc('id'); } if (!isAdminModule()) { $model = $model->where('status', '=', ModelStatusEnum::OK); } return $model; } }