Are you using the default AUTH provided by Laravel?
php artisan make:auth https://laravel.com/docs/5.5/authentication#included-views
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm using Laravel 5.5
i want to store the session data to the sessions table in the database & use it.
i changed the session_driver in config\session.php from file to database
'driver' => env('SESSION_DRIVER', 'database'),
and created the sessions table
php artisan session:table
here is my Login Controller :
public function login() {
// Authenticate the user
if(!auth()->attempt(request([
'email', 'password'
]), true)) {
return back()->withErrors(['message' => 'Incorrect email or password']);
}
// I think i should store the session to database here before returning to home page
// Return home
return redirect()->home();
}
i want after successful login store the session with it's data to the database (sessions) table
and use that session in the project e.g get user_agent, last_activity
How i can achieve something like that?
As your using the auth()->attempt(...) helper function, after a successful login the session should be automatically saved to the database. What is not working?
By setting the session driver to database any call to the session (helper) functions should resolve to the corresponding database result. (https://stackoverflow.com/questions/26166662/using-laravels-session-database/26168878#26168878). Maybe this helps you too: https://laracasts.com/discuss/channels/laravel/how-to-store-users-id-in-session-table-laravel-5
In addition, here's an old tutorial about the larval session, auth and cache functionality: https://code.tutsplus.com/tutorials/laravel-unwrapped-session-auth-and-cache--cms-19952.
Please or to participate in this conversation.