
Store logged in user details in session and display in view in laravel
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.
Answers 1
-
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 }}
0You 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.
Random Code Snippet Queries: Laravel
- Create project factory and seed data in laravel
- Class 'App\Providers\Auth' not found
- Laravel 7 login error message not showing
- How to get IP address in laravel
- If condition in foreach loop in laravel
- How to add active class to menu item in laravel
- SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
- How to get the id of last record from collection object in laravel view
- How to pass data to multiple partial view files in laravel
- How to access the nth object from Laravel collection object ?
- Class App\Http\Controllers\Admin\UserController Does Not Exist
- How to get route method name in Laravel
- Route [password.request] not defined
- Call to a member function pluck() on array
- How to pass data to route in laravel?
- Create record with unique slug in laravel
- How to avoid duplicate entries in pivot table in Laravel
- Check if Relationship Method Exists in Laravel
- Json encode method in laravel
- Call to undefined method Illuminate\Support\Facades\Request::all()
- Target class [App\Http\Controllers\Auth\Request] does not exist.
- Redirect to another view from controller in laravel
- How to get id of next record in laravel
- How to get all route list
- Illuminate\Database\QueryException could not find driver