How to display user profile after login in laravel

Updated at 22-Sep-2021, By samar

How to display user profile after login in laravel

In this tutorial, we will try to find the solution to "How to display user profile after login in laravel" through programming.

You can display user profile after login in laravel. You can get the user details using the Auth::user() helper function which you can call in the blade file.
  • Display user details in view file after login

    --PATH resources\views\<home>.blade.php
    //Display name of authenticated user
    {{ Auth::user()->name }}
    
    //Get logged in user id
    {{ Auth::user()->id  }} 
    
    //Display logged in user image
    @if( isset(Auth::user()->image) && file_exists('storage/'.Auth::user()->image))
        <img src="{{ asset('storage/'.Auth::user()->image) }}" alt="{{ Auth::user()->image }}">
    @else
        <img src="{{ asset('frontend/images/imagenotfound.jpg') }}" alt="...">
    @endif
    

    Auth::user() will work only if the user is authenticated/logged in else it will give an error.  To display the image you have to link the storage folder and check if the file exists in  /storage/{user_profile}.jpg and display using asset method.

Back to code snippet queries related laravel