dystcz/laravel-cookie-consent-history

This package allows you to simply store cookie consent history for users, so you can access it later in the unfortunate event of inspection or something.

v1.0.0 2022-01-27 13:20 UTC

This package is auto-updated.

Last update: 2024-03-27 17:49:17 UTC


README

Latest Version on Packagist Total Downloads

This packages aims to make it easy to store anonymous cookie consents in a database in order to comply with rather strict EU cookie policy laws. Your application will get the power of keeping consent history, so you will have no problem with your burden of proof process when someone complains about your cookie consents.

Installation

You can install the package via composer:

composer require dystcz/laravel-cookie-consent-history

Publish config and migrations, run migrations

php artisan vendor:publish --provider="Dystcz\CookieConsentHistory\CookieConsentHistoryServiceProvider"
php artisan migrate

Register package routes in some of your route files, but if you want to use your own routes and controller, that is completely fine.

// routes/api.php

use Dystcz\CookieConsentHistory\CookieConsentHistoryFacade;

CookieConsentHistoryFacade::routes();

Configuration

return [
    /**
     * The prefix for the table names.
     * You can use your own prefix here, eg. company_ if it were to conflict with existing table names.
     * We leave it empty, so the table name is cookie_consents by default.
     */
    'table_prefix' => '',

    /**
     * The prefix for routes.
     * There are only 2 routes, one for storing the consent data and one for retrieving.
     *
     * POST /cookie-consents (or your prefix) saves the consent
     * GET /cookie-consents/{id} gets the consent if exists
     */
    'route_prefix' => 'cookie-consents',

    /**
     * Model definition.
     * You can extend the base model to your needs.
     */
    'model' => Dystcz\CookieConsentHistory\Models\CookieConsent::class,
];

Usage

Storing consents

You can either register package routes, or you can introduce your own with your controller.

Below is an example store method which comes from Dystcz\CookieConsentHistory\Http\Controllers\CookieConsentsController.

/**
* Store cookie consent data.
*
* @param StoreCookieConsentRequest $request
*
* @return \Illuminate\Http\JsonResponse
*/
public function store(StoreCookieConsentRequest $request)
{
    // Create DTO out of validated request
    $data = new CookieConsentData(...$request->validated());

    $consent = CookieConsentHistory::save($data);

    return new JsonResponse([
        'data' => $consent,
    ]);
}

Complementary front end package

We aim to also provide a complementary javascript package, that will work nicely with this package making cookie law compliance as easy as possible.

Stay tuned.

Testing

Tests coming soon!

composer test

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jakub@dy.st instead of using the issue tracker.

Credits

License

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