认证相关路径由#AuthRouteMethods.php#登录退出$this->get('login','Auth\LoginController@showLoginForm')->name('login');$this->post('login','Auth\LoginController@login');$this->post('logout','Auth\LoginController@logout')->name('logout');#注册$this->get('register','Auth\RegisterController@showRegistrationForm')->name('register');$this->post('register','Auth\RegisterController@register');#重新设置密码$this->get('password/reset','Auth\ForgotPasswordController@showLinkRequestForm')->name('password.request');$this->post('密码/电子邮件','Auth\ForgotPasswordController@sendResetLinkEmail')->name('password.email');$this->get('password/reset/{token}','Auth\ResetPasswordController@showResetForm')->name('password.reset');$this->post('password/reset','Auth\ResetPasswordController@reset')->name('password.update');$this->get('密码/确认','Auth\ConfirmPasswordController@showConfirmForm')->name('password.confirm');$this->post('password/confirm','Auth\ConfirmPasswordController@confirm');#邮箱验证$this->get('email/verify','Auth\VerificationController@show')->name('verification.notice');$this->get('email/verify/{id}/{hash}','Auth\VerificationController@verify')->name('verification.verify');$this->post('email/resend','Auth\VerificationController@resend')->name('verification.resend');相关概念认证配置文件:config/auth.phpguardGuard:对用户进行认证,默认支持“session”和“token”,使用的provider可以在guard中设置。ProviderProvider:用于在数据库中查找用户的方法,默认支持“eloquent”和“database”,使用的模型类可以在guard中设置。模型类:默认为App\User::class。配置文件#config/auth.phpreturn['defaults'=>['guard'=>'web','passwords'=>'users',],'guards'=>['web'=>['driver'=>'session','provider'=>'users',],'api'=>['driver'=>'token','provider'=>'users','hash'=>false,],],'providers'=>['users'=>['driver'=>'eloquent','model'=>App\User::class,],],'passwords'=>['users'=>['provider'=>'users','table'=>'password_resets','expire'=>60,'throttle'=>60,],],'password_timeout'=>10800,];登记册使用Illuminate\Support\Facades\Auth;$user=User::create(['name'=>$data['name'],'email'=>$data['email'],'password'=>Hash::使($数据['PASsword']),]);$this->guard()->login($user);登录逻辑$credentials=$request->only('email','password');$credentials['active']=1;如果($this->guard()->attempt($credentials,$request->filled('remember'))){$request->session()->regenerate();returnredirect()->intended('dashboard');}退出逻辑$this->guard()->logout();$request->session()->invalidate();$request->session()->再生令牌();自定义守卫使用Illuminate\Support\Facades\Auth;受保护的函数guard(){//默认值:Auth::guard();//守卫名称需要与auth.php配置文件中的其中一个配置项匹配returnAuth::guard('guard-name');}获取认证用户useIlluminate\Support\Facades\Auth;//获取当前经过身份验证的用户...$user=Auth::user();//获取当前经过身份验证的用户ID...$id=Auth::id();//返回经过身份验证的用户实例...使用Illuminate\Http\Request;$request->user();检查用户是否通过身份验证useIlluminate\Support\Facades\Auth;if(Auth::check()){//用户已经登录...}其他登录方法//loginAuth::login($user);//登录记得指定用户...Auth::login($user,true);//指定guard实例登录Auth::guard('admin')->login($user);//通过ID将用户登录到应用程序Auth::loginUsingId(1);//登录并记住给定的用户...Auth::loginUsingId(1,true);//只对用户进行一次认证,不使用session或cookiesAuth::once($credentials)来保护路由Laravel自带一个auth中间件,定义在Illuminate\Auth\Middleware\Authenticate中,因为这个中间件已经在HTTP核心中,只需将这个中间件附加到路由定义中:Route::get('profile',function(){//只有经过身份验证的用户才能进入...})->middleware('auth');#或publicfunction__construct(){$this->middleware('auth');}在路由中添加auth中间件时,还可以指定使用哪个守卫进行用户认证。指定的guard应该对应auth.php配置文件中guards数组中的一个键:publicfunction__construct(){$this->middleware('auth:api');}