
[英]Laravel 5.3 Auth facade is changing to a default authenticated user
[英]Why is the Auth facade not imported by default in laravel route file
为什么不需要在 laravel 路由文件中导入 Auth facade?
导入它有什么影响?
<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
我为以后可能对此问题感兴趣的任何人找到了一个全面的答案。
在新的 Laravel 安装中默认不导入 Auth facade,因为 Laravel 使用 PHP 的命名空间系统来访问类和方法,并且 Auth facade 的别名是底层实现 class Illuminate\Support\Facades\Auth.
Auth facade 在config/app.php
文件中使用别名, Auth::routes()
方法包含在 routes/web.php 文件中,它为您的应用程序设置默认身份验证路由。
当你在你的应用程序中使用Auth::routes()
时,Laravel 将通过别名自动使用底层实现 class,而不需要你导入外观。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.