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

Athror's avatar

Disabling Cookie Encryption via Service Provider

Hi everyone, I am developing a package in Laravel 11, where I have to set up a cookie, that I need to read via GTM, so I need to be not encrypted. I know I can disable encryption in the middleware. But would be possible to add it via the package service provider? My objective is just to remove this additional step.

I am setting this cookie via livewire. Therefore I cannot disable cookie encryption middleware from the route. Any additional idea is welcome!

0 likes
4 replies
Athror's avatar

I found a solution!

    $this->app->afterResolving(EncryptCookies::class, function ($middleware) {
        $middleware->disableFor($cookieName);
    });

to be added in the boot() method in the service provider of the package.

1 like
puklipo's avatar
puklipo
Best Answer
Level 9
use Illuminate\Cookie\Middleware\EncryptCookies;

EncryptCookies::except('cookie_name');
sergbbb's avatar

in bootstrap/app.php

->withMiddleware(function (Middleware $middleware): void {
        $middleware->encryptCookies([
            'name_will_not_encrypt',
        ]);
    })

Please or to participate in this conversation.