Assume there are two types of users in our web application, one is a guest, and the other is the logged-in user. So in this example, we will see how we can check whether a user is logged in or not in the Laravel controller. So from this example, you will learn check if user is logged in laravel controller.

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

how-to-check-user-is-login-or-not-laravel-controller

Now see the example code of the controller:

app/Http/Controllers/TestController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class TestController extends Controller
{
    public function index()
    {   
        if(Auth::check()) {
            //user is logged in
        }

        if(auth()->check()) {
            //user is logged in
        }
    }
}

 

Read also: How To Check User Is Login Or Not In Laravel Blade

 

Conclusion

Now we know how to check whether the user is login or not in laravel controller. Hope this example tutorial will help you to check login user.

Category : #laravel

Tags : #laravel , #laravel auth