How to get get Auth User ID in Laravel Example

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this blog i will show you can how to get current login user in laravel application. Now here i will show how to get current user id in controller in laravel application. I also show you how to get in view files also. Her we can user auth() helper and auth facade class to get the current login user data in laravel application.

So here i will show you how to get current user data as like id by using laravel in laravel application. Now here i will give you two ways to get the current user data by using laravel authentication. So we can simply get logged in user details in controller or view blade files in laravel application.

Now we can get current user details by using laravel auth. So we can also use simple auth helper or use Auth facade. So here i will give you both example, now you can take any one as you want. Here I always require getting current logged in user data in laravel application.

So here the blow example of get auth user id in laravel application:

Example Using Facade

Now this example is using facade.

$user = Auth::user();

print($user->id);

Example Using Helper

Now this example is using facade.

$user = auth()->user();

print($user->id);

Read Also : Laravel Pagination with Ajax Example

Thank you read.Hope it will help you. Also follow on facebook

About code chef

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by code chef →