Laravel 5:关于404路线的会议 [英] Laravel 5: Sessions on 404 route
问题描述
这让我发疯了几个星期: 如何在404页上提供会话?我只是 在我的默认模板中嵌入404错误页面.它还显示了导航栏 和页脚,但是在使用404时如何保持我的用户登录?
This is driving me crazy for weeks now: How can I make sessions available on the 404 page? I just embed the 404 error page in my default template. It also shows the navbar and the footer but how can I keep my user logged in when on a 404?
在404上,Auth :: check()始终返回false,而会话其他特定内容为null或为空.
On a 404 Auth::check() always returns false and every else whats session specific is null or empty.
如何在(404)错误页面上启用会话?
How to enable sessions on (404) error pages?
推荐答案
您可以做的是,在app/http/Kernel.php内添加以下代码块:
What you can do is, inside the app/http/Kernel.php add the follwing block of code:
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
在$ middleware变量中.因此,它看起来像:
Inside the $middleware variable. So it would look like:
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
];
它对我有用,我希望它也对您有用.
It worked for me, I hope it works for you as well.
这篇关于Laravel 5:关于404路线的会议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!