Answer the question
In order to leave comments, you need to log in
Why is the session not being saved to the Laravel database?
Good day everyone!
I am writing here because I don’t understand at all what I did wrong or didn’t do at all.
It is necessary to save the session to the database after user authentication.
Further, everything is as described in the documentation:
LoginController and others are created via php artisan make:auth
Table sessions via migrations
--php artisan session:table
--php artisan migrate
session.php file
'driver' => env('SESSION_DRIVER', 'database'),
'connection' => env('SESSION_CONNECTION', null),
'table' => 'sessions',
Route::group(['middleware' => ['web']], function () {
Route::get('/sess', 'Auth\[email protected]'); (сделал тестовый, в нем никакой авторизации не происходит. Чисто пытался сохранить сессию)
Route::post('/login', 'auth\[email protected]')->name('login');
});
public function login(Request $request) {
if(Auth::attempt(['email'=>$request->email, 'password'=>$request->password])) {
if($request->session()->start()) {
$request->session()->put(['user_id' => 32324234234]);
$request->session()->save();
}
} else {
return 'Вы ввели неверный логин или пароль';
}
}
Answer the question
In order to leave comments, you need to log in
Try it:php artisan config:cache
It is necessary to save the session to the database after user authentication.why the base?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question