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


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

1 answer


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

Using the Auth Facade


Using the helper


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('/', '[email protected]');


Documentation: Route Groups

answered by 01.09.2018 / 03:10