How to Check User Login or Not in Laravel?

By Hardik Savani October 7, 2022 Category : Laravel

Hello Guys,

I am going to show you an example of laravel check user login or not. you will learn check user login or not in laravel blade. This article goes in detailed on check if user is logged in laravel controller. I would like to share with you how to check user login or not in laravel. follow the below example for how to check if user logged in laravel.

You can use this example with laravel 6, laravel 7, laravel 8 and laravel 9 versions.

If you are new and you trying to find how to detect user is login or not in your laravel application. So, it is very easy to check because laravel provide to Auth facade for check user is login or not. Check bellow example:

Example 1: Laravel Check User Login or Not in Blade File

@if (Auth::check())

<p>User is login.</p>

@else

<p>User is not login.</p>

@endif

@auth

<p>User is login.</p>

@endauth

Example 2: Laravel Check User Login or Not in Controller File

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Auth;

class DemoController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index(Request $request)

{

/* Example 1 */

if (Auth::check()) {

dd("User is login.")

} else {

dd("User is not login.")

}

/* Example 2 */

if (Auth::user()) {

dd("User is login.")

} else {

dd("User is not login.")

}

}

}

I hope it can help you...

Tags :