how to do so that when I log in laravel I return the user's data and it is stored in a session or a localstorage

2

Hi, I am new to laravel, I use laravel 5.6 I am implementing a login with function __construct(){$this->middleware('auth.basic');} is a basic authentication, this builder inserted it in canda controller. what I need is that every time the session starts, I return the user's data and they are stored in a session or in the localstorage (I do not know where it should be stored). so that when this user registers something, this record will be followed by the user's id and thus to know who kept that record. Thanks in advance

    
asked by Frank Campos Vilchez 31.08.2018 в 23:47
source

1 answer

2

If you are using Laravel authentication you can access the authenticated user's data by doing:

Using the Auth Facade

    \Auth::user()  

Using the helper

    auth()->user()

Documentation: Retrieving The Authenticated User

It is also not necessary to add middleware to all controllers. You can create a group of routes that implements the middleware and you're done.

// Todas las rutas definidas en este grupo van a tener el middleware auth
Route::middleware(['auth'])->group(function () {
    Route::get('/', 'HomeControler@index');

});

Documentation: Route Groups

    
answered by 01.09.2018 / 03:10
source