Answer the question
In order to leave comments, you need to log in
Why does Auth::user return null?
Good day. Faced such a problem, it is necessary that when going through the 'admin' route, the controller checks whether the user is authorized in the system, and if so, returns the user to the variable and gives access to the page, otherwise an error occurs. But Auth::user constantly gives me null, although the data is entered correctly and I remain authorized on the site, but Auth::user shows null. I'm new to Laravel, I don't understand why, here is the router code
Auth::routes();
Route::get('login', 'Auth\[email protected]');
Route::post('login', 'Auth\[email protected]');
Route::get('logout', 'Auth\[email protected]');
//Admin
Route::group(['prefix' => 'admin','middleware'=> 'auth'],function() {
//admin
Route::get('/',['uses' => 'Admin\[email protected]','as' => 'adminIndex']);
Route::resource('/articles','Admin\ArticlesController');
});
public function __construct()
{
$this->user = Auth::user();
if(!$this->user){
abort(403);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question