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

Laravel 6 , Laravel , Laravel 7

Nicesnippets

2868

18-06-2020


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..