PHPackages                             martin-schenk/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. [Localization &amp; i18n](/categories/localization)
4. /
5. martin-schenk/laravel-cookie-consent

ActiveLibrary[Localization &amp; i18n](/categories/localization)

martin-schenk/laravel-cookie-consent
====================================

GDPR-compliant cookie consent system with minimal dependencies for Laravel 11 and 12

v0.3.0(9mo ago)101.3k↓38.2%1MITPHPPHP ^8.2

Since May 27Pushed 4mo agoCompare

[ Source](https://github.com/martinschenk/laravel-cookie-consent)[ Packagist](https://packagist.org/packages/martin-schenk/laravel-cookie-consent)[ RSS](/packages/martin-schenk-laravel-cookie-consent/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

Laravel Cookie Consent
======================

[](#laravel-cookie-consent)

**A lightweight, GDPR-compliant cookie consent system with minimal dependencies for Laravel 11 and 12**

> Perfect for Laravel applications that need a simple, effective, and legally compliant cookie consent solution without the bloat of external JavaScript frameworks.

[![Latest Stable Version](https://camo.githubusercontent.com/bf3c61c9a47db10605c779c660045d96d37a600fe41b1d47783fb3a54ff6da12/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d617274696e2d736368656e6b2f6c61726176656c2d636f6f6b69652d636f6e73656e742e737667)](https://packagist.org/packages/martin-schenk/laravel-cookie-consent)[![Total Downloads](https://camo.githubusercontent.com/bd7543c5da23faf4709d2a72ffcb39fb56671363db0d9e58c07d5b2bc7819f96/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d617274696e2d736368656e6b2f6c61726176656c2d636f6f6b69652d636f6e73656e742e737667)](https://packagist.org/packages/martin-schenk/laravel-cookie-consent)[![Monthly Downloads](https://camo.githubusercontent.com/6bd60a6a161191f30c278a151826a12b77649eceb810e57a10a9fb493e7fbb1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d617274696e2d736368656e6b2f6c61726176656c2d636f6f6b69652d636f6e73656e742e737667)](https://packagist.org/packages/martin-schenk/laravel-cookie-consent)[![GitHub Stars](https://camo.githubusercontent.com/bb18331ba0c461af7205823c2658a4ed2402a94f5eb19beb50eb49a604cca219/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f6d617274696e736368656e6b2f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d736f6369616c)](https://github.com/martinschenk/laravel-cookie-consent)[![Laravel Version](https://camo.githubusercontent.com/a6874a9d36788f06a2b9c7b9a5559e19cf4dd5d445b327ba6e2038bf704f57c7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31312e7825323025374325323031322e782d7265642e737667)](https://laravel.com)[![PHP Version](https://camo.githubusercontent.com/1428e785ed3157b96c945a429648440f5e51f2fc18af16871670f16d71e3153e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d617274696e2d736368656e6b2f6c61726176656c2d636f6f6b69652d636f6e73656e742e737667)](https://packagist.org/packages/martin-schenk/laravel-cookie-consent)[![License](https://camo.githubusercontent.com/8860c3e0823a86bb571537ffe8c152227eb6d21fb9e9237d6d537f2b6b4e8f1f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d617274696e2d736368656e6b2f6c61726176656c2d636f6f6b69652d636f6e73656e742e737667)](LICENSE.md)[![GDPR Compliant](https://camo.githubusercontent.com/ca22648dff2c3068f3399774e75834cd00fdbd280605ccc8b821ca12e408b483/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f474450522d436f6d706c69616e742d626c75652e737667)](https://gdpr-info.eu/)

🎭 Live Demo
-----------

[](#-live-demo)

**Try it before you install it!** Check out our interactive demo to see the cookie consent system in action.

### 🚀 Quick Demo Access

[](#-quick-demo-access)

1. **Fastest way - Direct download:**

    ```
    curl -O https://raw.githubusercontent.com/martinschenk/laravel-cookie-consent/main/demo/index.html
    # Then open index.html in your browser
    ```
2. **Clone the repository:**

    ```
    git clone https://github.com/martinschenk/laravel-cookie-consent.git
    cd laravel-cookie-consent/demo
    ```
3. **Open the demo:**

    - **Option A:** Simply double-click the `demo/index.html` file
    - **Option B:** Serve it locally: ```
        # Using Python (if installed)
        python3 -m http.server 8080 --directory demo
        # Then open http://localhost:8080

        # Or using PHP (if installed)
        php -S localhost:8080 -t demo
        # Then open http://localhost:8080
        ```

The demo showcases:

- ✅ Cookie consent banner with Accept/Reject/Settings options
- ✅ Detailed cookie settings modal
- ✅ Pure vanilla JavaScript (no frameworks!)
- ✅ Smooth CSS transitions
- ✅ Consent status tracking
- ✅ Interactive buttons to test all features

📸 Screenshots
-------------

[](#-screenshots)

### Cookie Consent Banner

[](#cookie-consent-banner)

[![Cookie Consent Banner](screenshots/initial-modal-laravel-cookie-consent-martin-schenk.png)](screenshots/initial-modal-laravel-cookie-consent-martin-schenk.png)

### Cookie Settings Modal

[](#cookie-settings-modal)

[![Cookie Settings Modal](screenshots/edit-modal-laravel-cookie-consent-martin-schenk.png)](screenshots/edit-modal-laravel-cookie-consent-martin-schenk.png)

### GDPR Compliance: No Analytics Cookies on Load

[](#gdpr-compliance-no-analytics-cookies-on-load)

[![No Analytics Cookies on Initial Load](screenshots/initial-modal-with-dev-tools-laravel-cookie-consent-martin-schenk.png)](screenshots/initial-modal-with-dev-tools-laravel-cookie-consent-martin-schenk.png)

*Screenshot shows the cookie consent banner with developer tools open, confirming no Google Analytics cookies are loaded before user consent.*

✨ Highlights
------------

[](#-highlights)

- **Zero JavaScript dependencies** - Pure vanilla JavaScript, no Alpine.js, no Livewire, no Filament
- **Pure Vanilla JavaScript** - No framework dependencies, works with bare Laravel
- **Tailwind CSS Styling** - Beautiful, responsive design using Tailwind CSS classes
- **GDPR-compliant** - Legally sound implementation with opt-in for all cookie types
- **Multilingual** - German, English, Spanish and Chinese included
- **Google Analytics Integration** - Dynamic loading and removal of GA scripts
- **Locale Cookie Management** - Stores language preferences only with consent
- **Blade Components** - Easy integration into existing Laravel applications
- **Tailwind CSS** - Elegant, customizable design (optional)
- **Mobile-First** - Fully responsive for all devices

💻 Requirements
--------------

[](#-requirements)

- **Laravel**: Version 11.x or 12.x required - [Laravel Installation](https://laravel.com/docs/installation)
- **Tailwind CSS**: Version 3.x recommended - [Tailwind CSS for Laravel](https://tailwindcss.com/docs/guides/laravel)Tailwind CSS is recommended but not strictly required - the component will still work with your own CSS, but you'll need to modify the published views to match your styling framework.

### Checking Your Installed Versions

[](#checking-your-installed-versions)

Use these commands to verify your installed versions:

```
# Check Laravel version
php artisan --version

# Check Tailwind CSS version (if installed via npm)
npx tailwindcss --version

# No JavaScript framework version checks needed - uses pure vanilla JavaScript
```

🧠 How It Works
--------------

[](#-how-it-works)

This plugin provides a lightweight, GDPR-compliant cookie consent system for Laravel 11 and 12 - fully implemented with Blade and pure vanilla JavaScript. It works without any JavaScript framework dependencies - no Alpine.js, Livewire, Inertia, or other external dependencies.

### 🇪🇺 GDPR Compliance

[](#-gdpr-compliance)

The EU General Data Protection Regulation (GDPR) and similar privacy laws worldwide require explicit user consent before storing non-essential cookies. This package implements a fully compliant solution that:

- Blocks all non-essential cookies by default
- Provides clear opt-in choices for different cookie categories
- Allows users to change their preferences at any time
- Properly documents consent for compliance purposes

### 🌐 Google Analytics Integration

[](#-google-analytics-integration)

- The plugin blocks any connection to Google Analytics by default
- Only when a user explicitly consents to the "Analytics" category, the GA script (gtag.js) is dynamically inserted into the ``
- Website owners only need to enter their Google Tag ID (G-XXXXXXXXXX) - no additional customization required

### 🚫 Tracking Prevention When Declined

[](#-tracking-prevention-when-declined)

- When analytics consent is declined, the GA script is not loaded
- Additionally, the plugin attempts to delete all typical GA cookies, including:
    - \_ga, \_gid, *gat*\*
    - \_\_ga\*, \_\_gads
- Even if some cookies cannot be fully deleted for technical reasons (e.g., HttpOnly), no tracking will occur as the JavaScript is not loaded

**Result**: Google has no access to user interactions unless consent is given.

### 🇪🇸 Personal Preferences

[](#-personal-preferences)

The plugin currently stores a single preference: the language setting (locale).

- The language is automatically read from the `` attribute
- When the user consents to the preferences category, a `locale=xx` cookie is set (e.g., `locale=en`), which Laravel can use for automatic language switching
- If consent is revoked, the locale cookie is deleted

### 🔧 Technical Implementation

[](#-technical-implementation)

ComponentTechnologyUI / ModalsBlade + TailwindLogicVanilla JavaScriptConsent StoragelocalStorageCookie HandlingJavaScript (document.cookie)Language Detectiondocument.documentElement.langGA Activationdocument.createElement('script')GA BlockingNo script inclusion + Cookie deletion🚀 Installation
--------------

[](#-installation)

```
composer require martin-schenk/laravel-cookie-consent
php artisan vendor:publish --provider="MartinSchenk\CookieConsent\CookieConsentServiceProvider"
```

🔧 Configuration
---------------

[](#-configuration)

After publishing the package assets, you can configure the cookie consent system in `config/cookie-consent.php`:

```
// config/cookie-consent.php
return [
    'google_analytics_id' => '',  // Set your Google Analytics ID here (e.g. 'G-XXXXXXXXXX')

    'cookie_names' => [
        'consent' => 'cookieConsent',
        'locale' => 'locale',
    ],

    'cookie_lifetime' => 31536000,  // 1 year in seconds

    'categories' => [
        'essential' => true,  // Always required
        'analytics' => false, // Optional
        'preferences' => false, // Optional
    ],
];
```

You can modify the configuration values directly in the published configuration file:

📊 Usage
-------

[](#-usage)

Include the cookie consent component in your main layout file:

```

```

### Example Integration

[](#example-integration)

Here's how to integrate the cookie consent component in your Laravel layout:

```

        Cookie Settings

```

> **Note**: The cookie consent component should be placed before the closing `` tag to ensure all other elements are loaded first. This provides the best user experience.

🔗 Adding a Cookie Settings Link to Your Footer
----------------------------------------------

[](#-adding-a-cookie-settings-link-to-your-footer)

An important feature is the ability to reopen the cookie settings menu at any time. Here are different implementation options:

### Option 1: Direct JavaScript Call

[](#option-1-direct-javascript-call)

```

    Cookie Settings

```

### Option 2: For Complex Layouts (e.g., in a Vue or React component)

[](#option-2-for-complex-layouts-eg-in-a-vue-or-react-component)

```
// Trigger the cookie settings event
document.dispatchEvent(new CustomEvent('open-cookie-settings'));
```

### Option 3: Use as a Blade Component

[](#option-3-use-as-a-blade-component)

```
// In any of your Blade files:

```

### Practical Example: Typical Footer Implementation

[](#practical-example-typical-footer-implementation)

```

            Home
            Imprint
            Privacy Policy

                Cookie Settings

```

🌐 Supported Languages
---------------------

[](#-supported-languages)

This package comes with translations for:

- English (en)
- German (de)
- Romanian (ro)
- Spanish (es)
- Chinese (Simplified) (zh\_CN)

You can publish the language files to customize them:

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

🎨 Customizing Appearance
------------------------

[](#-customizing-appearance)

The cookie consent component uses Tailwind CSS by default. You can publish the views to customize the appearance:

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

💯 Why Choose This Package?
--------------------------

[](#-why-choose-this-package)

This plugin is the ideal solution for modern Laravel 11/12 projects that want to:

- Stay GDPR-compliant ✅
- Maintain maximum control ✅
- Avoid unnecessary external consent tools ✅
- Remain fully customizable and open-source ✅

🔍 Keywords
----------

[](#-keywords)

Laravel cookie consent, GDPR cookie banner, Laravel 11 cookie solution, Laravel 12 cookie solution, cookie consent manager, Laravel GDPR compliance, cookie opt-in system, vanilla JavaScript cookie consent, privacy cookie banner, EU cookie law Laravel, cookie consent popup, minimal cookie notice, lightweight cookie consent, Laravel cookie management, zero dependency cookie consent, no framework cookie banner

👥 Contributing
--------------

[](#-contributing)

**Contributions are highly welcome and appreciated!**

This project is open for contributions, and we would love for you to help make it better. Whether you want to fix a bug, add a new feature, improve the documentation, or just give feedback, your help is welcome.

Please see [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines on how to contribute to this project.

### 🌱 Good First Issues

[](#-good-first-issues)

Looking for something to work on? Issues labeled with [`good first issue`](https://github.com/martin-schenk/laravel-cookie-consent/labels/good%20first%20issue) are a great way to start contributing.

### 🗺️ Roadmap

[](#️-roadmap)

We're planning to add the following features in future releases:

- Support for additional cookie categories
- More styling options and themes
- Additional analytics services integration
- Cookie expiration management
- Support for older Laravel versions

Feel free to pick up any of these tasks or suggest new ones!

☕ Support this project
----------------------

[](#-support-this-project)

If this package made your life a little easier, you can [buy me a coffee](https://buymeacoffee.com/martinschenk) – or make my day by sending a little note:

📬 **Send a postcard to:**Martin Schenk Calle Hiruela 3, 5-7 28035 Madrid, Spain

Small gestures, big smiles. Danke! 💚

📝 License
---------

[](#-license)

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

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance67

Regular maintenance activity

Popularity27

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 96.4% 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 ~43 days

Total

3

Last Release

270d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2d14dacfc77900b8475b356a4f2d0c4dbe672a82cfdd65e2597e71d4b01c9c72?d=identicon)[Martin Schenk](/maintainers/Martin%20Schenk)

---

Top Contributors

[![martinschenk](https://avatars.githubusercontent.com/u/635827?v=4)](https://github.com/martinschenk "martinschenk (27 commits)")[![flavius-constantin](https://avatars.githubusercontent.com/u/23703860?v=4)](https://github.com/flavius-constantin "flavius-constantin (1 commits)")

---

Tags

laravelmultilingualtailwindcookiegoogle-analyticsgdprprivacyconsentCCPAcookie-banneralpine js

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[statikbe/laravel-cookie-consent

Cookie consent modal for EU

213396.7k](/packages/statikbe-laravel-cookie-consent)[typicms/base

A modular multilingual CMS built with Laravel, enabling developers to manage structured content like pages, news, events, and more.

1.6k20.3k](/packages/typicms-base)[devrabiul/laravel-cookie-consent

A GDPR-compliant cookie consent solution for Laravel applications with fully customizable cookie banners, granular consent control, and enterprise-grade compliance features.

17633.8k1](/packages/devrabiul-laravel-cookie-consent)[velstorelabs/velstore

Velstore - A multi-vendor, multi-lingual Laravel eCommerce boilerplate.

6301.3k](/packages/velstorelabs-velstore)

PHPackages © 2026

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