Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Fig Cookies

Fig Cookies Laravel Package

dflydev/fig-cookies

PSR-7 cookie helper for managing Cookie request headers and Set-Cookie response headers. Provides Cookies and SetCookies collections to read from requests/responses, modify cookie values/attributes, and render updated headers back into PSR-7 messages.

View on GitHub
Deep Wiki
Context7

Cookies for PSR-7 HTTP Message Interface.

Frequently asked questions about Fig Cookies
How do I integrate dflydev/fig-cookies into a Laravel middleware for handling incoming cookies?
Use `FigRequestCookies::fromRequest($request)` to parse cookies into immutable `Cookie` objects. Store them in middleware for later use, like authentication tokens. Example: `$token = FigRequestCookies::get($request, 'auth_token')->getValue();`
Can this package replace Laravel’s built-in `$request->cookie()` method in controllers?
Yes, but consider facades for business logic and middleware for cross-cutting concerns. For migration, wrap legacy calls with a trait like `LegacyCookieCompatibility` to reuse existing code while adopting the new API.
Does dflydev/fig-cookies support SameSite and Partitioned cookie attributes for modern browsers?
Yes, the package supports these attributes via `SetCookie::create()` methods. Ensure Laravel’s `Response` correctly renders headers by testing with `$response->getHeaders()` after setting cookies.
Will this package work with Laravel’s PSR-15 middleware (e.g., Psr15Middleware facade)?
Absolutely. The package is PSR-7 compliant and integrates seamlessly with Laravel’s PSR-15 middleware stack. Use `FigResponseCookies` to modify responses in middleware before they’re sent to the client.
How do I handle encrypted or serialized cookie values (e.g., JSON) with this package?
The package doesn’t enforce serialization, so pair it with Laravel’s `encrypt()` or `symfony/serializer` for sensitive data. Example: `SetCookie::create('user_prefs', encrypt($data))->withExpires(...)`.
Is there a performance overhead compared to manually parsing `$_COOKIE` or `$request->cookie()`?
Minimal overhead due to immutable objects, but facades add slight abstraction. For performance-critical paths, use primitives like `Cookie::fromString($cookieHeader)` directly. Benchmark with `laravel-debugbar` if needed.
Does this package work with Laravel’s HTTP client (e.g., sending cookies in outgoing requests)?
Yes, if your HTTP client uses PSR-7 messages (like Guzzle with PSR-18). Use `SetCookies::fromResponse()` to extract cookies from responses and `Cookies::renderIntoCookieHeader()` to attach them to outgoing requests.
How do I test cookie logic with dflydev/fig-cookies in PHPUnit or Pest?
Mock `Cookie` and `SetCookie` objects easily due to their immutable nature. Example: `$mockCookie = $this->createMock(Cookie::class); $mockCookie->method('getValue')->willReturn('test');` Then inject into `Cookies` collections for testing.
What Laravel versions are supported, and is PHP 8.x compatible?
The package requires PHP 7.4+ (Laravel 8+) for strict typing. It’s compatible with Laravel 8/9/10 and PSR-7 implementations like `symfony/http-foundation`. No PHP 8.x-specific features are required.
Are there alternatives to dflydev/fig-cookies for PSR-7 cookie handling in Laravel?
Laravel’s native `Request` and `Response` methods work, but this package offers a structured, immutable API for complex cookie logic. Alternatives like `league/cookie` exist but lack Laravel/PSR-7 integration. Choose this for middleware-centric or stateless API workflows.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky
spatie/mailcoach-vapor
spatie/laravel-javascript-views