Make your Laravel app comply with the refuse/accept cookie law

Overview

Make your Laravel app comply with the refuse/accept cookie law

Latest Version on Packagist Software License GitHub Workflow Status Total Downloads

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.

The users should be presented the option to agree or disagree with the optional cookies.

This package is based on the spatie/laravel-cookie-consent package by the good folks at Spatie.

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

Installation

You can install the package via composer:

composer require retinens/laravel-cookie-consent

The package will automatically register itself.

Optionally you can publish the config-file:

php artisan vendor:publish --provider="Retinens\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-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),
    
    /*
     * Use this setting to add a refuse button on the dialog.
    */
    'refuse_enabled' => env('COOKIE_CONSENT_REFUSE_ENABLED', false),

    /*
     * 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 * 1.
     */
    'cookie_lifetime' => 365 * 1,
];

Usage

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

//in your blade template
@include('cookie-consent::index')

This will render the following dialog that, when styled, will look very much like this one.

dialog

The default styling provided by this package uses TailwindCSS v2 to provide a floating banner at the bottom of the page.

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

Refuse button

If you want to add a refuse button to the dialog, you can enable the option in the config file. When the user clicks on "Refuse non-essential cookies" a laravel_cookie_consent cookie will be set with the value of 0.

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="Retinens\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-translations"

This will publish this file to resources/lang/vendor/cookie-consent/en/texts.php.

return [
    'message' => 'Please be informed that this site uses cookies.',
    'agree' => 'Allow cookies',
    'refuse' => 'Refuse non-essential cookies',
];

If you want to translate the values to, for example, French, just copy that file over to resources/lang/vendor/cookie-consent/fr/texts.php and fill in the French translations.

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="Retinens\CookieConsent\CookieConsentServiceProvider" --tag="cookie-consent-views"

This will copy the index and dialogContents view files over to resources/views/vendor/cookie-consent. 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

Instead of including cookie-consent::index in your view you could opt to add the Retinens\CookieConsent\CookieConsentMiddleware to your kernel:

// app/Http/Kernel.php

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

    // ...
}

This will automatically add cookie-consent::index to the content of your response right before the closing body tag.

Helper

In your code you can use the facade to get the info if the user has accepted or not the non-essential cookies.

CookieConsent::hasConsented();
CookieConsent::hasRefused();

That way you can (or not) add cookies for the user, or add scripts into the header.

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

Please see CHANGELOG for more information what has changed recently.

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security-related issues, please email [email protected] instead of using the issue tracker.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A package to easily make use of SVG icons in your Laravel Blade views.
A package to easily make use of SVG icons in your Laravel Blade views.

Blade Icons A package to easily make use of SVG icons in your Laravel Blade views. Originally "Blade SVG" by Adam Wathan. Turn... !-- camera.svg --

Make your own custom cast type for Laravel model attributes

Laravel Custom Casts Make your own cast type for Laravel model attributes Laravel custom casts works similarly to Eloquent attribute casting, but with

A package to easily make use of Iconsax in your Laravel Blade views.
A package to easily make use of Iconsax in your Laravel Blade views.

Blade Iconsax A package to easily make use of Iconsax in your Laravel Blade views. This package contains 1.000 icons in 6 diferent styles, a total of

A web app for detecting backend technologies used in a web app, Based on wappalyzer node module

About Techdetector This a web fingerprinting application, it detects back end technologies of a given domain by using the node module wappalyzer. And

CV-Resumes-App is helped us to build resume .. you can help me to improve this app...

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Podcastwala - Your very own Podcast web app built with Laravel. Manage and listen to your favorite podcasts
Podcastwala - Your very own Podcast web app built with Laravel. Manage and listen to your favorite podcasts

Podcastwala Your very own Podcast web app built with Laravel 5. This web app enables you to manage RSS feeds for your favorite podcasts and listen to

A package that makes it easy to have the `artisan make:` commands open the newly created file in your editor of choice.

Open On Make A package that makes it easy to have the artisan make: commands open the newly created file in your editor of choice. Installation compos

Make your accessors smarter

Computed properties for Eloquent Laravel 5.4+ Based on this tweet: https://twitter.com/reinink/status/899713609722449920 Some examples for better unde

Make your church sermons available for download.  For the latest version, go:
Make your church sermons available for download. For the latest version, go:

Laravel Church Sermons App Laravel church sermons app is basically an app for churches to make available the messages preached in church for all membe

Releases(4.1.2)
Owner
RETINENS - Multimedia solutions
RETINENS is a collective composed of creators and technicians of the audio-visual domain. We offer a multimedia support service for your organization.
RETINENS - Multimedia solutions
🍪 Laravel cookie consent history

?? Laravel cookie consent history This packages aims to make it easy to store anonymous cookie consents in a database in order to comply with rather s

Dystopia 3 Nov 9, 2022
🍪 Powerful wrapper for improved cookie integration on Laravel

?? Powerful wrapper for improved cookie integration on Laravel

Attla 1 Jul 16, 2022
PHP Simple Response, XML, JSON,... auto response with accept in request's header

simple-response Simple package to handle response properly in your API. This package does not include any dependency. Install Via Composer $ composer

Phuong Danh 3 Dec 8, 2021
Learn how to accept a payment from customers around the world with a variety of payment methods.

Accept a payment Learn how to securely accept payments online. This repository includes examples of 2 types of integration types. Prebuilt Checkout pa

Stripe Samples 337 Jan 2, 2023
Make requests to the Shopify API from your Laravel app

Make requests to the Shopify API from your Laravel app The signifly/laravel-shopify package allows you to easily make requests to the Shopify API. Ins

Signifly 147 Dec 30, 2022
Make any class queue aware in a Laravel app

Make any class queue aware This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. Support us We in

Spatie 8 Jun 17, 2022
A simple blog app where a user can signup , login, like a post , delete a post , edit a post. The app is built using laravel , tailwind css and postgres

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Nahom_zd 1 Mar 6, 2022
Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App.

OvalFi Laravel Package Laravel-OvalFi helps you Set up, test, and manage your OvalFi integration directly in your Laravel App. Installation You can in

Paul Adams 2 Sep 8, 2022
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

Malik Alleyne-Jones 17 Aug 25, 2022
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

UB Labs 12 Jan 17, 2022