How to Check User Login or Not in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Create Record if Not Exists Example
- Laravel 9 REST API with Passport Authentication Tutorial
- Laravel 9 Authentication using Jetstream Tutorial
- How to Send Mail using Sendinblue in Laravel?
- Laravel Livewire File Upload Tutorial
- How to Create Custom Error Page in Laravel 8?
- Laravel Login with Google Account Tutorial
- Laravel Facebook authentication using Socialite Package
- How to Add Charts in Laravel using Highcharts?
- Laravel Query Builder Where Exists Example
- How to Add Pagination with Union in Laravel?