spiral/cookies
PSR-7 cookie management for Spiral apps: create, encrypt/sign, and send cookies via a middleware-driven CookiesManager. Provides helpers for queueing and clearing cookies, supports secure defaults and seamless integration with Spiral HTTP workflows.
Install the package via Composer: composer require spiral/cookies. As a read-only subtree split of Spiral Framework, it provides secure cookie handling — typically used in HTTP middleware stacks. Start by registering the Spiral\Cookies\CookieMiddleware in your middleware pipeline (e.g., in App\Kernel). Then, inject Spiral\Cookies\CookieManager to read/write cookies securely. The first use case is usually setting a signed or encrypted cookie:
$cookies = $cookieManager->withDefaultSigner(new SecretSigner($secretKey));
$cookies->set('user_pref', 'dark_mode', ttl: 86400, secure: true, httpOnly: true);
CookieMiddleware early in the stack to automatically sign/verify cookies on each request. Configure it with a CookieSigner (e.g., SecretSigner for HMAC signing or EncrypterSigner for encryption).CookieManager into services/controllers to manage cookies explicitly, or use CookieAwareTrait in action classes for quick access.CookieManager::batch() to attach multiple cookies in a single response without manual iteration.SecretSigner signs only (detects tampering); use EncrypterSigner for confidentiality. Never store sensitive data unencrypted.set() call. Ensure clock synchronization across servers if using time-bound cookies.InvalidSignatureException) often stems from mismatched secret keys, timezone differences, or modifying cookie values client-side. Log $_COOKIE and middleware input/output to trace.CookieSignerInterface to implement custom signing logic (e.g., rotating keys, multi-tenant secrets). The CookieManager::withSigner() method allows per-request signer overrides.How can I help you explore Laravel packages today?