PHPackages                             amoori/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. amoori/cookie-consent

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

amoori/cookie-consent
=====================

Make your Laravel app comply with the crazy EU cookie law

0131PHP

Since Sep 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/AmirMehrabi/alravel-cookie-consent)[ Packagist](https://packagist.org/packages/amoori/cookie-consent)[ RSS](/packages/amoori-cookie-consent/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Make your Laravel app comply with the crazy EU cookie law
=========================================================

[](#make-your-laravel-app-comply-with-the-crazy-eu-cookie-law)

[![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)[![GitHub Workflow Status](https://camo.githubusercontent.com/61ff021f620ae41084bca45c240dddc09c6727e4578dea99e57afa337d76b05f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d636f6f6b69652d636f6e73656e742f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/61ff021f620ae41084bca45c240dddc09c6727e4578dea99e57afa337d76b05f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d636f6f6b69652d636f6e73656e742f72756e2d74657374733f6c6162656c3d7465737473)[![Total Downloads](https://camo.githubusercontent.com/d2088e6e946e46460f42678da6e8033773e005869ede871b5499ced7c13d4d46/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-cookie-consent)

All sites owned by EU citizens or targeted towards EU citizens must comply with a crazy EU law. This law requires a dialog to be displayed to inform the users of your websites how cookies are being used. You can read more info on the legislation on [the site of the European Commission](http://ec.europa.eu/ipg/basics/legal/cookies/index_en.htm#section_2).

This package provides an easily configurable view to display the message. Also included is JavaScript code to set a cookie when a user agrees with the cookie policy. The package will not display the dialog when that cookie has been set.

Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

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

[](#support-us)

Learn how to create a package like this one, by watching our premium video course:

[![Laravel Package training](https://camo.githubusercontent.com/4c7f3720a29525e627f6004ee367e55def510e45d18e6bc974725812fa5cf257/68747470733a2f2f7370617469652e62652f6769746875622f7061636b6167652d747261696e696e672e6a7067)](https://laravelpackage.training)

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="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,
];
```

Usage
-----

[](#usage)

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

```
//in your blade template
@include('cookieConsent::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)

Please be aware that the package does not provide any styling, this is something you'll need to do yourself.

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="lang"
```

This will publish this file to `resources/lang/vendor/cookieConsent/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/cookieConsent/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="views"
```

This will copy the `index` and `dialogContents` view files over to `resources/views/vendor/cookieConsent`. 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 `cookieConsent::index` in your view you could opt to add the `Spatie\CookieConsent\CookieConsentMiddleware` to your kernel:

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

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

    // ...
}
```

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

Notice
------

[](#notice)

The legislation is pretty very vague on how to display the warning, which texts are necessary, and what options you need to provide. This package will go a long way towards compliance, but if you want to be 100% sure that your website is ok, you should consult a legal expert.

Changelog
---------

[](#changelog)

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

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](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.

###  Health Score

16

—

LowBetter than 4% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity21

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/d13e7604eb51f7853fb77882c8cbeddef51bd7bd23a5650438012ca297cac950?d=identicon)[ammir](/maintainers/ammir)

---

Top Contributors

[![AmirMehrabi](https://avatars.githubusercontent.com/u/3878847?v=4)](https://github.com/AmirMehrabi "AmirMehrabi (2 commits)")

### Embed Badge

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

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

PHPackages © 2026

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