Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

panther12's avatar

Laravel Auth Session not working

Hi, I am using the stock auth controllers that come with the laravel installation. they redirect fine to dashboard, but the sessions are not working. First, the session driver was set to file, so I tried changing it to cookie, It is not setting a cookie too. I am using bitnami wamp stack, and using the laravel framework, that came with the stack. Can this be the problem? any settings that I overlooked? I am saying this because, I never had any problem working with sessions before, when I used WAMP Server and Installed laravel from command-line.

0 likes
9 replies
panther12's avatar

The following route is defined by default. I am not using it tough. I don't even know, what it does. It was just there out of the box.

Route::group(['middleware' => ['web']], function () {
    //
});
Snapey's avatar

Sessions only exist within web middleware so you need to make sure all your routes are in a route group that specifies 'web' as middleware

1 like
panther12's avatar

^ how do I do that? copy/paste all the routes inside the above group's function? or is there any other way?

jlrdw's avatar

I thought that this was in the documentation I may have mis-read the documentation.
Edit: Re-read docs, it is in the docs: The Default Routes File

The default routes.php file is loaded by the RouteServiceProvider and is automatically included in the web middleware group, which provides access to session state and CSRF protection. Most of the routes for your application will be defined within this file.
Maybe the last word file should be changed to group.

panther12's avatar

@Prez: Still didn't fix my problem though. Now, a laravel session cookie is being set(wasn't being set previously). However, if I use middleware authentication to protect my dashboard route, the route keeps redirecting back to login page. Never goes to Dashboard.

Any thoughts?

'middleware' => 'auth'
panther12's avatar

@Snapey:


Route::group(['middleware' => ['web']], function () {
    
    Route::get('/', function () {
    return view('welcome');
});

Route::get('dashboard',  ['middleware' => 'auth' , function () {
        
    return view('dashboard');
}]);


Snapey's avatar

Its a bit hard to follow, I would probably;

//public routes
Route::group(['middleware' => ['web']], function () {
    
    Route::get('/', function () {
        return view('welcome');
});

//logged-in routes
Route::group(['middleware' => ['web','auth']], function () {
    Route::get('dashboard', function () {
        return view('dashboard');
    });
});

I find this easier once I have a lot of routes.

1 like

Please or to participate in this conversation.