PHPackages                             spatie/laravel-cookie-consent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. spatie/laravel-cookie-consent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

spatie/laravel-cookie-consent
=============================

Make your Laravel app comply with the crazy EU cookie law

3.4.0(2mo ago)1.5k4.7M↓12%14018MITPHPPHP ^8.2CI passing

Since Jun 27Pushed 2mo ago24 watchersCompare

[ Source](https://github.com/spatie/laravel-cookie-consent)[ Packagist](https://packagist.org/packages/spatie/laravel-cookie-consent)[ Docs](https://github.com/spatie/cookie-consent)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/spatie-laravel-cookie-consent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (67)Used By (18)

Simple, customizable cookie consent message for Laravel
=======================================================

[](#simple-customizable-cookie-consent-message-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0f33039ffdcb02fa9b53aca588dec4e6bf1528639c3f36b57c66bbaa0fc1e8df/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-cookie-consent)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![run-tests](https://github.com/spatie/laravel-cookie-consent/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-cookie-consent/actions/workflows/run-tests.yml)[![Total Downloads](https://camo.githubusercontent.com/d2088e6e946e46460f42678da6e8033773e005869ede871b5499ced7c13d4d46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-cookie-consent)

This package adds a simple, customizable cookie consent message to your site. When the site loads, the banner appears and lets users consent to cookies. Once consent is given, the banner hides and stays hidden.

**What this package does not:**

- Include an option to 'Decline' all cookies, which might be required.
- Block trackers and cookies before consent. You need to handle this yourself.
- Include options for different consent categories like "Necessary" or "Marketing".

For more advanced cookie consent options in Laravel, consider these alternatives.

- [whitecube/laravel-cookie-consent](https://github.com/whitecube/laravel-cookie-consent)
- [statikbe/laravel-cookie-consent](https://github.com/statikbe/laravel-cookie-consent)
- [devrabiul/laravel-cookie-consent](https://github.com/devrabiul/laravel-cookie-consent)

If you need an implementation of cookie consent for [Filament](https://github.com/filamentphp/filament) you can evaluate this plugin:

- [marcogermani87/filament-cookie-consent](https://github.com/marcogermani87/filament-cookie-consent)

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/685e21957db26bf55d76432e281d3e5014652a203a122a742fee2dd42c0f35df/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d636f6f6b69652d636f6e73656e742e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-cookie-consent)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-cookie-consent
```

The package will automatically register itself.

Optionally you can publish the config-file:

```
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-config"
```

This is the contents of the published config-file:

```
return [

    /*
     * Use this setting to enable the cookie consent dialog.
     */
    'enabled' => env('COOKIE_CONSENT_ENABLED', true),

    /*
     * The name of the cookie in which we store if the user
     * has agreed to accept the conditions.
     */
    'cookie_name' => 'laravel_cookie_consent',

    /*
     * Set the cookie duration in days.  Default is 365 * 20.
     */
    'cookie_lifetime' => 365 * 20,
];
```

The cookie domain is set by the 'domain' key in config/session.php, make sure you add a value in your .env for SESSION\_DOMAIN. If you are using a domain with a port in the url such as 'localhost:3000', this package will not work until you do so.

Usage
-----

[](#usage)

To display the dialog all you have to do is include this view in your template:

```
//in your blade template
@include('cookie-consent::index')
```

This will render the following dialog that, when styled, will look very much like this one.

[![dialog](https://camo.githubusercontent.com/3f1bae8c77ef942da75bfc02f1150ff152614488e5dfde3bc14f991d39f9a33a/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d636f6f6b69652d636f6e73656e742f696d616765732f6469616c6f672e706e67)](https://camo.githubusercontent.com/3f1bae8c77ef942da75bfc02f1150ff152614488e5dfde3bc14f991d39f9a33a/68747470733a2f2f7370617469652e6769746875622e696f2f6c61726176656c2d636f6f6b69652d636f6e73656e742f696d616765732f6469616c6f672e706e67)

The default styling provided by this package uses TailwindCSS v2 to provide a floating banner at the bottom of the page.

When the user clicks "Allow cookies" a `laravel_cookie_consent` cookie will be set and the dialog will be removed from the DOM. On the next request, Laravel will notice that the `laravel_cookie_consent` has been set and will not display the dialog again

Customising the dialog texts
----------------------------

[](#customising-the-dialog-texts)

If you want to modify the text shown in the dialog you can publish the lang-files with this command:

```
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-translations"
```

This will publish this file to `resources/lang/vendor/cookie-consent/en/texts.php`.

```
return [
    'message' => 'Please be informed that this site uses cookies.',
    'agree' => 'Allow cookies',
];
```

If you want to translate the values to, for example, French, just copy that file over to `resources/lang/vendor/cookie-consent/fr/texts.php` and fill in the French translations.

### Customising the dialog contents

[](#customising-the-dialog-contents)

If you need full control over the contents of the dialog. You can publish the views of the package:

```
php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-views"
```

This will copy the `index` and `dialogContents` view files over to `resources/views/vendor/cookie-consent`. You probably only want to modify the `dialogContents` view. If you need to modify the JavaScript code of this package you can do so in the `index` view file.

Using the middleware
--------------------

[](#using-the-middleware)

Instead of including `cookie-consent::index` in your view you could opt to add the `Spatie\CookieConsent\CookieConsentMiddleware` to your kernel:

In Laravel 11 open /bootstrap/app.php and register them there:

```
    ->withMiddleware(function (Middleware $middleware) {
        $middleware->append(\Spatie\CookieConsent\CookieConsentMiddleware::class);
    })
```

In Laravel 9 and 10 you can add them in app/Http/Kernel.php:

```
// app/Http/Kernel.php

class Kernel extends HttpKernel
{
    protected $middleware = [
        // ...
        \Spatie\CookieConsent\CookieConsentMiddleware::class,
    ];

    // ...
}
```

This will automatically add `cookie-consent::index` to the content of your response right before the closing body tag.

Notice
------

[](#notice)

We are not lawyers and can't provide legal advice. Consult legal professionals what rules apply to your project.

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [Willem Van Bockstal](https://github.com/willemvb)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

### Positioning the cookie banner (fixed / floating)

[](#positioning-the-cookie-banner-fixed--floating)

By default, the banner is rendered in the normal page flow. If you prefer a floating banner that stays visible regardless of page length, you can position it using CSS.

Add the following styles to your main stylesheet or Tailwind configuration:

```
.js-cookie-consent {
    position: fixed;
    bottom: 24px;
    right: 24px;
    max-width: 420px;
    padding: 16px 20px;
    background: #111827;
    color: #ffffff;
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
    z-index: 9999;
}

.js-cookie-consent a {
    color: #93c5fd;
    text-decoration: underline;
}

.js-cookie-consent button {
    background: #2563eb;
    color: #ffffff;
    border: none;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
}

.js-cookie-consent button:hover {
    background: #1d4ed8;
}

@media (max-width: 640px) {
    .js-cookie-consent {
        right: 12px;
        left: 12px;
        bottom: 12px;
        max-width: unset;
    }
}
```

###  Health Score

75

—

ExcellentBetter than 100% of packages

Maintenance83

Actively maintained with recent releases

Popularity69

Solid adoption and visibility

Community43

Growing community involvement

Maturity90

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 70% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~55 days

Recently: every ~179 days

Total

65

Last Release

86d ago

Major Versions

0.0.1 → 1.0.02016-06-28

v1.x-dev → 2.0.02017-08-30

2.12.13 → 3.0.02021-03-26

PHP version history (8 changes)0.0.1PHP ^7.0

1.0.0PHP ^5.5|^7.0

1.3.0PHP ^5.6|^7.0

2.6.3PHP ^7.1

2.7.0PHP ^7.2

2.12.10PHP ^7.3|^8.0

3.0.0PHP ^8.0

3.3.0PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (149 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (7 commits)")[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (6 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (5 commits)")[![willemvb](https://avatars.githubusercontent.com/u/1336390?v=4)](https://github.com/willemvb "willemvb (3 commits)")[![akoepcke](https://avatars.githubusercontent.com/u/5311185?v=4)](https://github.com/akoepcke "akoepcke (3 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (3 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (3 commits)")[![sebastiandedeyne](https://avatars.githubusercontent.com/u/1561079?v=4)](https://github.com/sebastiandedeyne "sebastiandedeyne (3 commits)")[![blite](https://avatars.githubusercontent.com/u/442226?v=4)](https://github.com/blite "blite (2 commits)")[![svenluijten](https://avatars.githubusercontent.com/u/11269635?v=4)](https://github.com/svenluijten "svenluijten (2 commits)")[![marcogermani87](https://avatars.githubusercontent.com/u/998645?v=4)](https://github.com/marcogermani87 "marcogermani87 (2 commits)")[![moathdev](https://avatars.githubusercontent.com/u/48479218?v=4)](https://github.com/moathdev "moathdev (1 commits)")[![nobiit](https://avatars.githubusercontent.com/u/45024177?v=4)](https://github.com/nobiit "nobiit (1 commits)")[![Numair25](https://avatars.githubusercontent.com/u/146667039?v=4)](https://github.com/Numair25 "Numair25 (1 commits)")[![themsaid](https://avatars.githubusercontent.com/u/4332182?v=4)](https://github.com/themsaid "themsaid (1 commits)")[![pcmanik](https://avatars.githubusercontent.com/u/28068540?v=4)](https://github.com/pcmanik "pcmanik (1 commits)")[![peterangelov](https://avatars.githubusercontent.com/u/1159427?v=4)](https://github.com/peterangelov "peterangelov (1 commits)")[![rakibdevs](https://avatars.githubusercontent.com/u/44586913?v=4)](https://github.com/rakibdevs "rakibdevs (1 commits)")

---

Tags

cookieeujavascriptlaravelphpspatiecookiecookie-consenteulawcomply

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-laravel-cookie-consent/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-laravel-cookie-consent/health.svg)](https://phpackages.com/packages/spatie-laravel-cookie-consent)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.7k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[retinens/laravel-cookie-consent

Make your Laravel app comply with the crazy EU cookie law

354.5k](/packages/retinens-laravel-cookie-consent)[spatie/laravel-schedule-monitor

Monitor scheduled tasks in a Laravel app

9815.7M9](/packages/spatie-laravel-schedule-monitor)[spatie/laravel-multitenancy

Make your Laravel app usable by multiple tenants

1.3k2.9M16](/packages/spatie-laravel-multitenancy)[spatie/laravel-feed

Generate rss feeds

9743.6M28](/packages/spatie-laravel-feed)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
