Laravel 5 how to view the contents of the blade on the guest / authenticated user?

advertisements

I can read from the documentation that I can write the following in order to understand if the user is authenticated :

if (Auth::check())
{
 // The user is logged in...
}

Until there everything is working for me (authentication)

What I still miss is how should I manage the authentication with blade. In order, for example to display a different menu, if the user Is or isn't authenticated.

But I wouldn't duplicate all my blade templates to obtain the above. I would like to understand how to place conditions(where controller or view?) in order to display (yeld) different content based on current auth status

e.g. the pseudo code I have in mind for my app.blade.php file:

....
<body >
     @if (Auth::check())
     {
     @include('menu')
     @yield('content')
     }@else{
     @include('menu.guest')
     }
</body>

is this the good way?

Thanks


yes you can check it like that, but you have few errors in your code, you cant use curly brackets in blade template. Do something like this.

<body >
     @if (Auth::check())
         @include('menu')
         @yield('content')
     @else
         @include('menu.guest')
     @endif
</body>