Assume there are two types of pages, one is for guests and one is for only authenticated users. So in this example, we will see how we can check whether a user is logged in or not in the Laravel application. So from this example, you will learn how to check user is login or not in laravel 9. 

Sometimes we need to check that how to check user is login or not in laravel blade. So if you don't know then see the example code of checking laravel 9 check user login or not.

how-to-check-user-is-logged-in-or-not

Use this code in your blade file to check whether user is logged in or not in laravel:

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Laravel</title>
    </head>
    <body>
  
    @auth
		<!-- User is logged in -->
	@endauth

    @if(auth()->check())
        <!-- User is logged in -->
    @endif

    @guest
        <!-- User is guest -->
    @endguest
	 
    </body>
</html>

 

Read also: Laravel Get Logged In User ID In Controller

 

Conclusion

Now we know how to check user is login or not in laravel application. Hope this example tutorial will help you to get login user data.

Category : #laravel

Tags : #laravel , #laravel auth