Make your Laravel app comply with the crazy EU cookie law
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.
Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.
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. We publish all received postcards on our virtual postcard wall.
This is the contents of the published config-file:
/* * 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,
To display the dialog all you have to do is include this view in your template:
//in your blade template
This will render the following dialog that, when styled, will look very much like this one.
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
If you want to modify the text shown in the dialog you can publish the lang-files with this command:
Using the middleware
Instead of including cookieConsent::index in your view you could opt to add the Spatie\CookieConsent\CookieConsentMiddleware to your kernel:
This will automatically add cookieConsent::index to the content of your response right before the closing body tag.
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.
Please see CHANGELOG for more information what has changed recently.