![](/img/trans.png)
[英]Laravel - I Auth::user() in Authenticate.php Middleware return null
[英]Laravel - I can't find the Authenticate Middleware
我是Laravel的新手,正如标题所述,我找不到身份验证中间件。 我知道它应该在app / http / middleware / Authenticate中,就像以前的项目一样,但是不存在。 那里有:加密..,RedirectifAuth ..和VerifyCsrf ...希望您能帮助我找到它。
Laravel 5.2
'app / http / middleware / Authenticate.php'
Laravel 5.3
'app / exceptions / handler.php'
除非您对正在执行的操作有深入的了解, 否则建议您不要移动或覆盖供应商文件夹中的文件。
话虽如此,您可以覆盖Authenticate.php文件,而只需修改Kernel.php文件即可:
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \Illuminate\Auth\Middleware\Authenticate::class, <--Change this Directory
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
...
];
至:
/**
* The application's route middleware.
*
* These middleware may be assigned to groups or used individually.
*
* @var array
*/
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class, <--- There you go
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
...
];
确保将代码从供应商文件夹中的Authenticate文件复制并粘贴到app \\ http \\ middleware目录中的Authenticate文件中,以恢复相同的功能。
同样,不建议您执行此操作,除非您对正在执行的操作及其全部工作方式有深入的了解。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.