validate([ 'username' => 'required', 'password' => 'required' ]); $auth = $this->guard(); $user = PartyUser::where('username', $request->input('username'))->first(); if ($user && Hash::check($request->input('password'), $user->getRawOriginal('password'))) { $auth->login($user); return back()->with('flash_message', '登录成功'); } return back()->withErrors('用户名或密码错误')->withInput(['username' => $request->input('username')]); } public function logout() { $this->guard()->logout(); return back()->with('flash_message', '已退出'); } protected function guard() { return Auth::guard('web'); } }