Home > Back-end >  Adding if Auth in custom 404 blade file
Adding if Auth in custom 404 blade file

Time:01-08

In 404.blade.php, I wanna add @if(auth()->user()->type == 'admin') but it doesn't have auth variable in it. How to add it?

@if(auth()->user()->type == 'admin')
<a href="{{ url('admin') }}">Back to Main Page</a>
@else
<a href="{{ url('home') }}">Back to Main Page</a>
@endif

CodePudding user response:

Global middleware for error pages

You can move the StartSession middleware to the global middleware section.

This can be achieved by moving \Illuminate\Session\Middleware\StartSession::class from protected $middlewareGroups['web'] to protected $middleware[]

In app/Http/kernel.php:


// From
protected $middlewareGroups = [
    'web' => [
        ...
        \Illuminate\Session\Middleware\StartSession::class, // <-- this class
        ...
    ],
];


// To
protected $middleware = [
    ...
    \Illuminate\Session\Middleware\StartSession::class,
    ...
];

CodePudding user response:

one way (of many)

 @if(Auth::user()->type == 'admin')
    <a href="{{ url('admin') }}">Back to Main Page</a>
@else
  <a href="{{ url('home') }}">Back to Main Page</a>
@endif
  •  Tags:  
  • Related