
Store logged in user details in session and display in view in laravel
Store logged in user details in session and display in view in laravel
Good day, guys. In this post, we’ll look at how to solve the "Store logged in user details in session and display in view in laravel" programming puzzle.
You can use the session facade in laravel to store the logged-in user details and display in view file using the get method on session.-
Store logged in user details using session and display in view in laravel
<p>Import Auth and Session facade in the controller before definition</p> use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Auth; //Code in controller's method After login attempt $user = Auth::user(); Session::put('user', $user); //Display details in view file @php $loggedInUser = Session::get('user') @endphp //Get id of logged in user {{ $loggedInUser->id }}
You can get the logged user details by calling Auth::user() method and you can insert the user's details in the session by calling Session::put() method. Now You can get the user's details in the view file by calling Session::get() method by passing the session name which we have used while creating and get detail by passing the field's name to it.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.
Random Code Snippet Queries: Laravel
- How to get session in blade Laravel ?
- Get only 10 records from table in laravel
- Laravel create multiple records in Pivot table
- How to check find method executed successfully in laravel
- If condition in foreach loop in laravel
- How to get file extension from input type file in laravel
- How to get specific columns using with method in laravel Eloquent relationship
- How to Get records between two dates in Laravel
- Laravel URL validation not working
- The use statement with non-compound name 'Auth' has no effect
- Split an Eloquent Collection by half in Laravel
- Get 30 days older records from table in laravel
- How to use or operator in laravel
- Update last created record in Laravel
- Get laravel version
- Composer create project laravel/laravel example app
- The POST method is not supported for this route. Supported methods: PUT.
- Database transactions in laravel
- How to create and run user seeder in laravel
- How to validate URL with https using regex in laravel
- SQLSTATE[42S22]: Column not found: 1054 Unknown column 'users.post_id' in 'where clause
- Cast Array to an Object in Controller and then pass to view in laravel
- How to remove P tag from CkEditor in Laravel?
- Retrieve count of nested relationship data in Laravel
- Insert current date time in a column using Laravel