How to add GDPR Cookie Consent in Laravel
The GDPR (General Data Protection Regulation) is an EU EU’s General Data Protection Regulation.
GDPR Personal data includes names, email, addresses, numbers, information about appearance, health, and location, as well as online identifiers such as cookies, IP addresses, search, and browser history.
Also read: How to Create a Cookie Consent Popup in JavaScript
composer require spatie/laravel-cookie-consent
To display the dialog all you have to do is include this view in your template :
#resources/views/index.blade.php
@include('cookieConsent::index')
#Publish Services php artisan vendor:publish --provider="Spatie\CookieConsent\CookieConsentServiceProvider" --tag="lang"
#Change Message #resources/lang/vendor/cookieConsent/en/texts.php return [ 'message' => 'Your experience on this site will be improved by allowing cookies.', 'agree' => 'Allow cookies', ];
Including cookieConsent::index in your view and add the Spatie\CookieConsent\CookieConsentMiddleware to your kernel:
#app/Http/Kernel.php
class Kernel extends HttpKernel
{
protected $middleware = [
...
\Spatie\CookieConsent\CookieConsentMiddleware::class,
];
}