我创建了一个自定义 404 错误页面,并使用 app.layout 来包装它。
但这很奇怪,因为当我收到 404 错误页面时,即使我已登录,也会看到登录和注册链接。这是为什么?
update
当我登录我的页面并写入不存在的路由时,我得到带有扩展布局的 404 页面,但 Laravel 似乎无权访问 Auth::class 并且它看不到用户是否登录。
因此,我看到的不是“注销”链接,而是“登录”和“注册”链接
检查您的 app.layout 是否包含导航部分。
像这样的布局 html:
<div class="content-wrapper">
<!-- Content Header (Page header) -->
@include('partials.crumble_head')
<!-- Main content -->
<section class="content">
@yield('content')
</section>
<!-- /.content -->
</div>
如果您的内容页面扩展了此布局,那么粒子将不会消失
您好,答案需要根据我们讨论的内容进行更新。
Open app/Http/Kernel.php. Add below block to the $middleware
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
所以你的代码应该是这样的:
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
];
现在您应该能够在views/errors/404.blade 页面中访问Auth。确保在 Auth 之前添加“\”。例如:
{{\Auth::user()->name}}
https://laracasts.com/discuss/channels/laravel/getting-authuser-on-custom-404-page
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)