---
title: "Laravel Cookie Consent: Blade Setup Guide 2026 | CookieBeam"
description: "Add a GDPR-compliant cookie banner to Laravel: Blade stacks for scripts, blocking trackers, reading consent past EncryptCookies, and Consent Mode v2."
url: "https://cookiebeam.com/guides/laravel-cookie-consent-guide-2026"
lang: "en"
last_updated: "2026-10-17T18:54:20.491Z"
---

# Laravel Cookie Consent: Blade Setup Guide 2026

Laravel renders Blade on the server, so the tag your team pasted into the master layout head fires on every request before consent. Here's how to control script placement with Blade stacks, gate server-side tracking, and read a JS-set consent cookie past Laravel's cookie encryption.

In a Laravel app, the tracking tags almost always live in one place: the `<head>` of the master Blade layout. That's convenient, and it means Google Analytics or a Meta Pixel renders into every server response and runs the instant the page loads, before a visitor has agreed to anything. Laravel's server-rendered model also gives you a second surface most consent guides ignore: server-side tracking, queued jobs firing conversion events, and pixels you send from PHP, none of which a browser-side banner can touch.

The compliance risk is real. France's CNIL fined SHEIN 150 million euros in September 2025, partly because trackers fired before any choice and continued after "Reject all" ([CNIL](https://www.cnil.fr/en/cookies-placed-without-consent-shein-fined-150-million-euros-cnil)). If your Laravel app serves the EU, the UK, or a US opt-out state, you need to control both surfaces.

Place the CookieBeam loader as the first element in `<head>`, loaded synchronously before GTM, analytics, or other scripts. Do not add `async` or `defer`, and exclude it from script-delay optimizers.

## Blade stacks give you script control

Blade layouts use `@extends`, `@section`, and `@yield` to compose pages. For scripts, the tool you want is stacks. Declare a named stack in the layout head with `@stack('scripts')`, then have any child view push into it with `@push('scripts')`, `@prepend('scripts')`, or the dedupe-safe `@pushOnce` and `@prependOnce` ([Laravel Blade docs](https://laravel.com/docs/12.x/blade)). That lets a single page add its own tracking without editing the global layout, and it keeps ordering predictable. Your own bundled assets come in through the `@vite` directive, which is separate from third-party tags.

## Where the consent loader goes

Put the loader in the head of your master layout (commonly `resources/views/layouts/app.blade.php`), as the first script and before the `@stack` that pages push into. It has to initialize before the tags it controls.

```
<!-- resources/views/layouts/app.blade.php -->
<head>
  <meta charset="utf-8">
  <!-- FIRST, before @vite and any tracker -->
  <script src="https://cdn.cookiebeam.com/banner/YOUR_BANNER_ID/default/loader.js"></script>
  @vite(['resources/css/app.css', 'resources/js/app.js'])
  @stack('head-scripts')
</head>
```

Replace `YOUR_BANNER_ID` with your banner's public ID from the dashboard.

## Block trackers until consent

Load trackers in a disabled state and switch them on after opt-in. CookieBeam activates any script tagged `type="text/plain"` with a `data-category` once the visitor accepts. Push page-specific tags into the stack:

```
<!-- resources/views/products/show.blade.php -->
@pushOnce('head-scripts')
  <script
    type="text/plain"
    data-category="analytics"
    data-src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXX">
  </script>
@endPushOnce
```

The browser ignores a `text/plain` script until the consent runtime enables it, so a rejected visit loads nothing. See [how to block scripts before consent](https://cookiebeam.com/guides/how-to-block-scripts-until-cookie-consent).

## Reading the consent cookie in PHP (mind EncryptCookies)

Here's the Laravel-specific trap. The consent banner sets a plain cookie in the browser, but Laravel's `EncryptCookies` middleware expects every incoming cookie to be encrypted. When it hits a cookie it can't decrypt, it discards it, so `$request->cookie('cb_cookie')` comes back `null` even though the browser is sending it. The fix is to exclude the consent cookie (named `cb_cookie` by default) from encryption. In Laravel 11 and 12, do that in `bootstrap/app.php`:

```
// bootstrap/app.php
->withMiddleware(function (Middleware $middleware) {
    $middleware->encryptCookies(except: ['cb_cookie']);
})
```

Now you can read it and gate server-side work:

```
$raw = $request->cookie('cb_cookie');
$analytics = false;
if ($raw) {
    $data = json_decode($raw, true);
    $analytics = in_array('analytics', $data['categories'] ?? [], true);
}

// Always run the functional logic; only track with consent
if ($analytics) {
    SendServerSideConversion::dispatch($order);
}
```

Wrap this in middleware if you check it on many routes. The cookie reflects consent at request time, so pair server checks with the client-side blocking above. More on this split in [server-side consent enforcement](https://cookiebeam.com/guides/server-side-consent-enforcement).

## Consent Mode v2 with GTM

For Google Ads or GA4 on EEA or UK traffic, Consent Mode v2 has been required since March 2024. Set defaults to `denied` in the layout head before GTM loads:

```
<!-- resources/views/layouts/app.blade.php, after the loader -->
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('consent', 'default', {
    ad_storage: 'denied',
    analytics_storage: 'denied',
    ad_user_data: 'denied',
    ad_personalization: 'denied',
    wait_for_update: 500
  });
</script>
<!-- GTM container snippet goes here -->
```

CookieBeam applies the defaults and fires the `update` on acceptance. The [GTM consent setup guide](https://cookiebeam.com/guides/google-tag-manager-consent-complete-setup-2026) covers the container side.

## Livewire and Inertia

If you run Livewire or Inertia, remember that both update the page without a full reload after the first load. The consent loader in your master layout still initializes once, which is fine, but any component that mounts a tracker on render needs to check consent with `window.CookieBeam.acceptedCategory('analytics')` or listen for the `cookiebeam:consentUpdate` event rather than assuming a fresh page load gates it. Treat these like a single-page app for the interactive parts. The [SPA consent guide](https://cookiebeam.com/guides/cookie-consent-single-page-apps-spa-2026) covers that timing.

## Policy and testing

Publish a cookie policy route and link it from the banner and footer, and keep the cookie table honest as you add integrations (a scanner does this automatically, see [scanning versus manual audits](https://cookiebeam.com/articles/automated-cookie-scanning-vs-manual-audit-2026)). Then test:

- Load a fresh private window from an EU IP and confirm only necessary cookies exist before you interact. Laravel's own `XSRF-TOKEN` and session cookies are functional and expected.
- Reject, and verify no `_ga` or `_fbp` appears and no server-side conversion jobs dispatch.
- Accept, and confirm tags load and Consent Mode reports granted.

CookieBeam blocks unknown scripts by default and stores a timestamped consent record, so a Laravel app clears the same audit a purpose-built platform would. Run a full [consent audit](https://cookiebeam.com/guides/how-to-run-cookie-consent-audit-2026) after any new package, and check the [GDPR cookie compliance checklist](https://cookiebeam.com/guides/gdpr-checklist) before launch.
