Laravel Get Logged in User Data

To retrieve/get logged in user data on controller, blade view in laravel; Through this tutorial, you will learn how to get/retrieve logged in user data from database or session on controller and blade view file in laravel 10, 9, 8, 7.

How to Get Logged in User Data in Laravel

There are 4 ways to get/retrieve logged in user data from database or session on blade view and controller in laravel 10, 9, 8, 7; are following:

  • To Get Logged In User in Controller using Helper
  • To Get Logged In User in Controller using Facade
  • To Get Logged In User in View Blade using Helper
  • To Get Logged In User in View Blade using Facade

To Get Logged In User in Controller using Helper

Using the helper, you can get logged In user data on controller in laravel:

    public function index(Request $request)
    {
   
        /* Current Login User Details */
        $user = auth()->user();
        var_dump($user);
      
        /* Current Login User ID */
        $userID = auth()->user()->id; 
        var_dump($userID);
          
        /* Current Login User Name */
        $userName = auth()->user()->name; 
        var_dump($userName);
          
        /* Current Login User Email */
        $userEmail = auth()->user()->email; 
        var_dump($userEmail);
    }

To Get Logged In User in Controller using Facade

Using the facade, you can get logged In user data on controller in laravel:

    public function index(Request $request)
    {
        /* Current Login User Details */
        $user = Auth::user();
        var_dump($user);
      
        /* Current Login User ID */
        $userID = Auth::user()->id; 
        var_dump($userID);
          
        /* Current Login User Name */
        $userName = Auth::user()->name; 
        var_dump($userName);
          
        /* Current Login User Email */
        $userEmail = Auth::user()->email; 
        var_dump($userEmail);
    }

To Get Logged In User in View Blade using Helper

Using the helper, you can get logged In user data on blade view in laravel:

<p> User ID: {{ auth()->user()->id }} </p>
<p> User Name: {{ auth()->user()->name }} </p>
<p> User Email: {{ auth()->user()->email }} </p>

To Get Logged In User in View Blade using Facade

Using the facede, you can get logged In user data on blade view in laravel:

<p> User ID: {{ Auth::user()->id }} </p>
<p> User Name: {{ Auth::user()->name }} </p>
<p> User Email: {{ Auth::user()->email }} </p>

Conclusion

Through this tutorial, you have learned how to get/retrieve logged In user data from database or session on controller and blade view file in laravel 10, 9, 8, 7.

Recommended Laravel Tutorials

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

Your email address will not be published. Required fields are marked *