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

jbardnz's avatar

Issue with Laravel session domain

So here is the situation, I want to add a subdomain to my site e.g. new.example.com

In order to share the laravel_session cookie between my new subdomain and my original domain I need to update "domain" in session.php

Current I have this:

'domain' => null

and I am updating it to this:

'domain' => '.example.com'

This all works great if I clear all my cookies and test this setup. However when I push this to production I will have 1000's of users with existing cookies. It seems Laravel gets confused and tries to authenticate with the old cookie with the domain 'example.com' rather than use the new cookie at '.example.com'. This causes users to not be able to login until they clear their cookies.

The most obvious solution to me was to delete the older cookie. This is the code I currently have, but the cookie is not deleted:

\Cookie::queue(\Cookie::forget('laravel_session', '/', 'example.com'));

Has anyone come across this issue before and has any ideas on how to handle this?

0 likes
1 reply
prasadchinwal5's avatar

@jbardnz had same issue on Laravel 5.7. My solution was to have a global middleware which forgets the cookie

I used this method to unset and worked perfectly for me

unset($_COOKIE['Hello']);

Please or to participate in this conversation.