Hello Devs,
In this tutorial, we are going to learn how to check auth guard in laravel.
Follow this step by step guide given below:
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}}
I hope this example helps you.