How to check auth guard in Laravel ? | Laravel Check Login Guard

Admin   Laravel   203  2021-03-16 01:00:05

Hi Guys,

In this example,I will learn you how to check auth guard in larravel.you can easy and simply ckeck login guard in laravel.

The Auth Guards are a vastly unexplored part of most Laravel applications, since the ones that come by default already do a great job to log in users.

Check Blade :

 

@if(Auth::guard('admin')->check())

Hi {{Auth::guard('admin')->user()->name}}

@elseif(Auth::guard('user')->check())

Hi {{Auth::guard('user')->user()->name}}

@endif

Check Controller :

 

if(Auth::guard('admin')->check()){

dd(Auth::guard('admin')->user()->name);

}

elseif(Auth::guard('user')->check()){

dd(Auth::guard('user')->user()->name);

}

Get Controller :

 

public function index(){

$userName = Auth::guard('admin')->user()->name;

dd($userName);

}

Get Blade :

 

Hi {{Auth::guard('admin')->user()->name}}

It will help you..