Last updated on February 17, 2018
As part of Laravel 5.5 version release, Laravel introduced new blade directives called @auth and @guest.As the name implies both can be useful to determine if the current user is authenticated or guest.
In the previous versions of Laravel to check user authentication status we’d used @if
directive with the combination of Auth()->check()
. But the new directives makes code lot cleaner, lets see how we can use them.
@auth and @guest
Now we can quickly check if the current user is authenticated or is a guest:
// usign @guest @guest guest stuff here @else logged user stuff here @endauth // using @auth @auth logged user stuff here @else guest stuff here @endauth
old way of auth status check
@if (auth()->check()) @endif