Laravel 7: Why isn't my session cookie getting set in a browser?
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
Laravel Session Cookie Mystery: Why Your Browser Ignores the Set-Cookie Header
As a senior developer working with full-stack applications, debugging subtle HTTP interactions can often be more frustrating than complex algorithmic problems. You receive the correct server response—the essential Set-Cookie header is present—yet your browser silently ignores it. This scenario is extremely common when dealing with cross-origin requests between a backend (like Laravel) and a frontend SPA (like NuxtJS).
This post dives deep into why this discrepancy occurs, focusing specifically on the difference between testing via Postman versus a real browser environment, and how security settings interact with session management in Laravel.
The Postman vs. Browser Discrepancy Explained
The core of your question lies in understanding the difference between a raw HTTP client (Postman) and a full web browser.
When you use Postman, you are essentially sending a request directly to the server. While Postman can receive and display response headers like Set-Cookie, it does not execute the full cookie lifecycle managed by the browser's security model. Postman simply reports what the server sent back in the stream of data.
However, a web browser operates under much stricter security protocols governed by the Same-Origin Policy (SOP) and various cookie flags (Secure, HttpOnly, SameSite). When a browser receives a Set-Cookie header, it must evaluate that header against its current security context before accepting and storing the cookie.
The Role of Security Flags in Cookie Acceptance
Your provided session configuration shows:
'secure' => false,
'http_only' => false,While setting secure to false allows cookies to be set over HTTP (which is often problematic if you intend to use HTTPS), the primary reason a browser might ignore a cookie is usually related to Cross-Origin Resource Sharing (CORS) or Cookie Attributes.
1. Cross-Origin Context
Since your Laravel server (localhost:8000) and NuxtJS SPA (localhost:7000) are on different ports, they are cross-origin. For a cookie to be successfully sent and received across this boundary, the request must involve appropriate CORS preflight checks (if using complex headers) and the browser's security policies must permit the transfer.
2. The SameSite Attribute
Modern browsers heavily enforce the SameSite attribute on cookies. If you are dealing with cross-origin communication, setting SameSite=Lax or Strict dictates whether the cookie is sent along with cross-site requests. If your application logic doesn't correctly handle session state across these domains, the browser may refuse to persist the session cookie for security reasons.
Debugging Laravel Session Setup
Looking at your session.php, the configuration itself seems standard for a basic setup:
'cookie' => 'dv_session',
'path' => '/',
'domain' => "", // Empty domain implies it targets the current host context.The issue is rarely in this file; it’s almost always in how the request was initiated or how the browser interprets the security context of that request.
Actionable Steps for Resolution
To resolve this, focus your debugging efforts on these areas:
- Enforce HTTPS: For any production environment (and often even local development if you are simulating a real deployment), ensure you are running over HTTPS. If
secureis set tofalse, the browser will reject setting cookies unless strict CORS rules are met, especially in modern contexts. - Check CORS Configuration: Ensure your Laravel routes handling session creation are correctly configured to allow requests from
http://localhost:7000. Review your CORS middleware setup. Proper configuration is vital when building secure APIs, a principle highlighted by best practices found on platforms like laravelcompany.com. - Inspect Network Tab: The most definitive way to confirm the failure is to use the browser's Developer Tools (F12) and inspect the Application tab -> Cookies. Watch precisely what cookies are being accepted or rejected by the browser after the request is made.
Conclusion
The phenomenon of a cookie working in Postman but failing in a browser is a classic symptom of a mismatch between raw HTTP transmission and the strict security policies enforced by web browsers. It’s rarely an error in Laravel's session logic itself, but rather a consequence of how cross-origin security (CORS, SameSite, Secure flags) interacts with the cookie setting mechanism. By focusing on hardening your CORS setup and ensuring correct protocol usage (HTTPS), you can ensure that your sessions are reliably persisted by the client.