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

Makka's avatar
Level 2

Subdomain single auth across all sub's & main not working?

Hello, I'm building a site with a dynamic subdomain system eg (name.domain.com). im using Ubuntu with laravel's serve command.

ive set it all up in my routes as so:


Route::domain('{x}.localhost')->group(function (){
    Route::get('/url/',  'SomeController@someAction')->middleware('can:xyz,x')->name('someName');
});

Now, everything works great, apart from the fact Auth is subdomain locked eg(xyz.localhost:8000/ , localhost:8000/ , 127.0.0.1:8000) all require separate logins.

after a bit of googling I read, I can overite this in the config/session.php file under 'domain'. So in my .env file I set up a new var for SESSION_DOMAIN and point it to ".localhost" or ".localhost:800" or the same with 127.0.0.1 / :8000 as suggested however when I try to login my session is not valid right after login eg( i log in and get redirected to the correct route but my auth catches that I'm not logged in)

SESSION_DOMAIN=.localhost

It seems like no cookies are being set for some reason?

-- edit, should probably note this is happening using both files and the database for sessions, ive also cleared out my cache and session storage each time along with cookies etc.

Any suggestions? Kind regards, Matt

0 likes
3 replies
Makka's avatar
Level 2

Bump - Still stuck on this one, any help would be great!

Please or to participate in this conversation.