Ad

Auth()->user() Is Null In Laravel 5.2

- 1 answer

I just update the composer to Laravel 5.2 and not able to view password protected pages. Basically below line of code is not working.

auth()->user() 

Can somebody suggest why this is not working ?

Ad

Answer

Make sure any routes that require sessions (which Auth uses) are behind the 'web' middleware group.

Route::group(['middleware' => 'web'], function () {
    // your routes
});

This is a change that is new to 5.2. By default routes do not have this middleware stack applied. The web middleware group sets the session store, cookies, and csrf protection.

Ad
source: stackoverflow.com
Ad