senses / laravel-gdpr
Laravel package for under the hood management of GDPR permission cookies.
Installs: 92
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/senses/laravel-gdpr
Requires
- php: ^7.0|^8.0
- illuminate/cookie: ^7.0|^8.0|^9.0
- illuminate/support: ^7.0|^8.0|^9.0
- illuminate/view: ^7.0|^8.0|^9.0
This package is auto-updated.
Last update: 2025-10-28 20:47:01 UTC
README
Laravel package to handle management of cookies via type. Heavily inspired by Spatie's laravel-cookie-consent package
Installation
composer require senses/laravel-gdpr
In config/app.php
// Add to service providers array Senses\Gdpr\GdprServiceProvider::class, // Add to aliases array 'Gdpr' => Senses\Gdpr\GdprFacade::class,
Usage
Backend
In your layout file, include the @gdprjs directive somewhere inside your <body> tag.
You can then use the directive @gdpr('category') which acts as an if statement based on whether or not the user has accepted the cookie.
You can publish the package's config to config/gdpr.php with php artisan vendor:publish.
php artisan vendor:publish --provider="Senses\Gdpr\GdprServiceProvider"
The default categories for cookies are:
'types' => [ 'necessary', 'functional', 'analytics', 'settings' ]
You can change this in your published config, along with the cookie name and lifetime.
You can disable the plugin by setting GDPR_ENABLED to false in your .env. file.
Frontend
Provided the @gdprjs directive is present, you can manipulate the gdpr settings via javascript.
The package binds a laravelGdpr object to the window object. Allowing you to work with the package from there.
It's best to reload the page once you're done changing these settings in order for the user's configuration to come into effect.
The laravelGdpr object has two methods inside it:
laravelGdpr.get() will return the user's entire config.
laravelGdpr.set(category, value) accepts two parameters, category and value. value should be boolean.
The package is frontend-agnostic, allowing you to use your own CSS and JS to construct the GDPR permissions modal.
When one of your toggles or checkboxes is changed, you will need to call the laravelGdpr.set() method.
Quick Example:
document.querySelector('input[type="checkbox"]#third_party').addEventListener('click', function(e) { laravelGdpr.set('third_party', e.target.checked); });
There is a full example Vue component available on codesandbox