Reputation: 5720
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
Upvotes: 2
Views: 3058
Reputation: 540
You can use blade directives take a look
@auth
// The user is authenticated...
@endauth
Upvotes: 1
Reputation: 4236
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>
Upvotes: 1
Reputation: 479
Yes this way is good when you are using same template. You can also make separate file and include as per your authentication status.
Upvotes: 0