Posts Learn Components Snippets Categories Tags About
/

Laravel Blade @auth Example

Learn how to check for authenticated user in Laravel using @auth directive

Created on Aug 06, 2021

47 views

It's very common to check whether a user is authenticated in Laravel by using the "@if" blade directive. But instead of writing the logic which is quite long, you can easily make use of the "@auth" to replace it.

The common way using "@if" blade directive.
@if (auth()->user())
    // the user is authenticated
@endif

When using "@auth" blade directive.
@auth
    // the user is authenticated
@endauth

Snippets by

PostSrc poster

PostSrc

Full stack developer mainly focusing on the front end side of the web. The main author of PostSrc and loves writing tutorial and guides online.

Load comments for Laravel Blade @auth Example

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your project.

View Components

Other Code Snippets

More