ItSolutionStuff.com

How to Check User Login or Not in Laravel?

By Hardik Savani • April 16, 2024
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, laravel 9, laravel 10 and laravel 11 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: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Create Record if Not Exists Example

Read Now →

Laravel 9 REST API with Passport Authentication Tutorial

Read Now →

Laravel 9 Authentication using Jetstream Tutorial

Read Now →

How to Send Mail using Sendinblue in Laravel?

Read Now →

Laravel Livewire File Upload Tutorial

Read Now →

How to Create Custom Error Page in Laravel 8?

Read Now →

Laravel Login with Google Account Tutorial

Read Now →

Laravel Facebook authentication using Socialite Package

Read Now →

How to Add Charts in Laravel using Highcharts?

Read Now →

Laravel Query Builder Where Exists Example

Read Now →

How to Add Pagination with Union in Laravel?

Read Now →