request = $request; } /** * @param $model * @param RepositoryInterface $repository * * @return mixed */ public function apply($model, RepositoryInterface $repository) { if ($this->request->filled('name')) { $model = $model->where('name', 'like', '%' . $this->request->get('name') . '%'); } if ($this->request->filled('is_read')) { $model = $model->where('is_read', '=', $this->request->get('is_read')); } else { $model = $model->where('is_read', '=', UserMessage::IS_READ_NO); } if ($this->request->filled('type')) { $model = $model->where('type', '=', $this->request->get('type')); } if ($this->request->filled('guard') || $this->request->header('guard')) { $guard = $this->request->get('guard', $this->request->header('guard')); $user = Auth::guard($guard)->user(); $model = $model->where('user_id', $user->id)->where('user_type', get_class($user)); } else { $user = login_admin(); $model = $model->where('user_id', $user->id)->where('user_type', get_class($user)); } $model = $model->orderByDesc('id'); return $model; } }