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
- Target class [admin] does not exist.
- Laravel onclick function not working
- How to customize or Change validation error messages
- Link storage folder in laravel 8
- Call to a member function getRelationExistenceQuery() on array in Laravel
- How to display user profile after login in laravel
- How to insert multiple rows in mysql using loop in laravel?
- Laravel route redirect not working
- How to display a specific word from a string in laravel
- Best Practices for Error Handling in Production Server Code (example code)
- How to create static page in Laravel
- Laravel order by date not working
- Call to a member function update() on null
- Get domain name in laravel
- RuntimeException You must enable the openssl extension in your php.ini to load information from https://repo.packagist.org
- Symlink(): No such file or directory
- How to fill a column automatically while creating records in Laravel
- Send id with route Laravel
- Method Illuminate\Database\Eloquent\Collection::lists does not exist
- Laravel URL validation not working
- How to get route name on visit URL in laravel
- How to upload multiple images after preview in laravel using cropper js
- Get current month records in laravel 7/8
- Insert current date time in a column using Laravel
- Database transactions in laravel