Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/Http/Controllers/ResetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@

namespace Whitecube\LaravelCookieConsent\Http\Controllers;

use Illuminate\Support\Facades\Cookie;
use Whitecube\LaravelCookieConsent\CookiesManager;
use Illuminate\Http\Request;

class ResetController
{
public function __invoke(Request $request, CookiesManager $cookies)
{
$response = ! $request->expectsJson()
$exclude = ['XSRF-TOKEN', 'laravel-session'];

$keys = array_filter(
array_keys($request->cookies->all()),
fn($key) => !in_array($key, $exclude, true)
);

$response = !$request->expectsJson()
? redirect()->back()
: response()->json([
'status' => 'ok',
'scripts' => $cookies->getNoticeScripts(true),
'notice' => $cookies->getNoticeMarkup(),
]);

return $response->withoutCookie(
cookie: config('cookieconsent.cookie.name'),
domain: config('cookieconsent.cookie.domain'),
);
foreach ($keys as $key) {
$response->withoutCookie(
cookie: $key,
domain: config('cookieconsent.cookie.domain'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this cope with cookies not related to the defined cookieconsent.cookie.domain?

Copy link
Contributor Author

@Debatty-Tom Debatty-Tom Oct 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After several tests, I realised that passing the recommended domain in the configuration file also handles the subdomain reset.
config('cookieconsent.cookie.domain') should look like this .domain.comand not domain.com

);
}

return $response;
}
}