Tauras
Tauras

Reputation: 3904

Delete cookie not working if cookie is set to all subdomains on same domain

I am creating cookie like that:

Cookie::queue(Cookie::make('cookie_name', 'cookie_value', 60, '/', '.domain.com'));

As i understand, cookie is set to domain globally, i mean, that this cookie will work with subdomains also. For example: example.domain.com

However, i can't delete it, if i am initiating deletion on subdomain.

Cookie::queue(Cookie::forget('cookie_name'));

How can i do that?

Thanks for any answers.

Upvotes: 2

Views: 2003

Answers (2)

Dharmesh Rakholia
Dharmesh Rakholia

Reputation: 1238

You can use this code to remove the cookie

$cookie = Cookie::forget('cookie_name', null, '.domain.com');
return response()->json(['success' => true, 'message' => 'You are successfully logged out.'])->withCookie($cookie);

Upvotes: 0

Onix
Onix

Reputation: 2179

Try this:

Cookie::queue('cookie_name', null, -1);
return Redirect::route('your_route');

Upvotes: 3

Related Questions