Download the PHP package scify/laravel-cookies-consent without Composer

On this page you can find all versions of the php package scify/laravel-cookies-consent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cookies-consent

Laravel Cookies Consent Plugin - Make your Laravel app compliant with the EU GDPR cookie law


Latest Version on Packagist GitHub Tests Action Status Total Downloads GitHub Issues GitHub Stars GitHub forks contributions welcome License Maintenance Ask Me Anything ! GitHub contributors GitHub pull-requests GitHub closed pull-requests

Table of Contents

Upgrading to v4

As of February 2025, The v4 of the Laravel Cookies Consent plugin has been released! 🎉🥳😍

In order to upgrade to v4, please follow the instructions in the CHANGELOG file, and consult also the How To Upgrade to a New Major Version file.

About the plugin

According to the GDPR law, every platform is required to allow the users to decide which cookie categories they will allow, and, if a cookie category is not allowed, the application should not use the functionality tied to that cookie.

This plugin provides a simple cookie consent window through which the user can specify the cookies they would like to allow.

After the user submission, the page reloads and the relevant cookies are set on the browser, and can then be used in the front-end.

Features

Installation

You can install the package via composer:

Make sure to manually publish the cookie image file, by running:

Notice: if a new version of the plugin has been released, and you want to update the front-end files, please make sure to use --force option, to overwrite the file.

By doing so, the image file will be copied to public/vendor/scify/laravel-cookies-consent.

IMPORTANT:

You can then either decide to include the public/vendor/scify/laravel-cookies-consent/* files to git (especially if you want to edit it first), or add it to .gitignore, and make sure to also run this command on the staging/production server.

Next, you need to publish the config file:

The configuration file will be published to config/cookies_consent.php.

Explanation of the configuration file

In the config file, you can change the cookie categories of your application, set the required and pre-selected categories, as well as add new categories.

This is the contents of the published config file:

The cookie_prefix is optional and, if set, will be applied to every cookie.

If set, a good strategy is to also add a trailing underscore "_", that will be added between the field value, and each cookie.

For example, if cookie_prefix is set to my_app_, then the targeting cookie will have a value of my_app_cookies_consent_targeting.

The display_floating_button field is optional and, if set to true, will display a floating button in the bottom right corner of the page. If set to false, then you will need to add a relevant link in your footer, in order to show the cookies preferences page:

The hide_floating_button_on_mobile field is optional and, if set to true, will hide the floating button on mobile

The use_separate_page field is optional and, if set to true, will display the cookies preferences in a separate page.

The categories_collapsed_by_default field is optional and, if set to false, will initially collapse the optional categories. If set to true, all categories will be collapsed by default.

You can add as many cookie categories as you like, simply by adding values to the cookies array.

If you want to remove a cookie category, simply remove it from the array.

You can use the enabled array to set the cookie categories that will be pre-selected, and the required array to set the cookies that the user won't be able to deselect.

If you want to change how long the cookies will be stored, edit the cookie_lifetime variable.

Usage

Option 1: All-in-one dialog (default)

Suitable for: Apps that would like to show a single dialog with all the cookie categories.

When the plugin is installed, a laravel-cookies-consent custom Laravel View Component is automatically registered.

This will render the following cookies consent that, will look very much like this one.

You can then use this component in order to display the cookies consent window, wherever you'd like.

Typically, a good strategy is to put the component just before the closing <body> tag:

(Or you can put the scripts in the <head> tag, if you prefer).

Option 2: Simple dialog, with a link to the default separate internal page

Suitable for: Apps that would like to show a simple "Accept all/Reject Optional" dialog with a link to a separate page for customizing the cookies preferences.

Edit the config/cookies_consent.php file, and set the use_separate_page field to true.

When the plugin is installed, a /cookie-policy/{locale} route is automatically registered. So, you can edit the config/cookies_consent.php file, and set the use_separate_page field to true.

Now, the user will see a simple dialog, with a link to the /cookie-policy/{locale} page, where they can customize their cookies preferences. This page is managed by the plugin, and it will show the cookies categories, descriptions, and the ability to accept or reject them.

Option 3: Simple dialog, with a link to a customized separate internal page with navbars, footers, etc.

Suitable for: Apps that would like to show a simple "Accept all/Reject Optional" dialog with a link to a customized page, with the app's own content (navigation, footer, etc).

If you would like to show a simple "Accept all/Reject Optional" dialog with a link to a separate page for customizing the cookies preferences, you can set the following in the config/cookies_consent.php file:

Or you can declare your route to override the default one:

And then create a new route in your routes/web.php file:

Then, you can create a new route in your routes/web.php file:

Now, in the resources/views/my-custom-cookies-policy.blade.php file, you will need to render the x-laravel-cookies-consent-page component, in order to show the cookies preferences dialog.

Here is a usage example:

Option 4: Simple dialog, with a link to an external (off-the-app) page

Suitable for: Apps that would like to show a simple "Accept all/Reject Optional" dialog, with a link to an external URL.

If you would like to show a simple "Accept all/Reject Optional" dialog with a link to an external URL, you can set the following in the config/cookies_consent.php file:

How to override the CSS styles

If you want to override the CSS styles of the cookies consent dialog, you can do this:

Then, you can add a <style> tag in your Blade file, in order to override the CSS styles:

The full list of CSS variables that can be overridden can be found in the public/vendor/scify/laravel-cookies-consent/_variables.css file.

How to add a new cookie category

In order to add a new cookie category, you need to add a new entry in the cookies array in the configuration file:

Or, you can set the description to be null (or an empty string), or set a translation key directly, like so:

  1. Create a cookies-specific translation file:

Contents:

Then, in your config/cookies_consent.php file, you can set the description fields to be the translation keys. Notice that the description fields have cookies.google_analytics.* values: (from the cookies.php file we just created).

How to check if a cookie category is allowed

Backend code

You can use the $_COOKIE global object, in order to check for the appropriate cookie.

Now you can use this object in your Blade files like this:

For example, An application that wants to load the Google Analytics script only if the user has given their consent to the targeting cookie category, might do the following:

In this example, we checked whether the $_COOKIE[config('cookies_consent.cookie_prefix') . 'cookies_consent_targeting'] key exists or not.

Frontend code

You can use the window.localStorage object, in order to check for the appropriate cookie. (declared in the configuration file)

Customization

Customizing the component texts

If you want to modify the texts shown in the cookies dialog, you can publish the language resource files with this command:

This will publish the translation files to lang/vendor/scify/laravel-cookies-consent/ directory.

The plugin comes with many built-in languages. You can change the translations for a given language, or add additional languages yourself.

Customizing the component contents

If you need full control over the contents of the cookies dialog, you can publish the views of the package:

This will copy the view files over to resources/views/components/vendor/scify/laravel-cookies-consent directory.

Development

In order to locally run the package, you should use a local Laravel application, in which you are going to install it.

Make sure that the composer.json file of the Laravel app has the following entry:

This will tell composer that the code for the package is of the "@dev" version and that it exists in the specified path.

Then run:

To fetch the local package.

Or, to prune everything and re-install:

Testing

This project uses Pest for testing. To execute the test suite, run:

FAQ

Question: Is this plugin free to use?

Answer: Yes. This plugin is totally free and developed as an Open-Source project.


Question: How long do the cookies last?

Answer: The duration is set in days, in config/cookies_consent.php file. In order to publish this file, run

The configuration file will be published to config/cookies_consent.php.

Then, edit the cookie_lifetime field (in days).


Question: Will the cookie consent window show every time?

Answer: No. As soon as the user clicks one of the "Accept all", "Accept selection", or "Decline all", the selection will be stored in another cookie, and the window won't pop up again, until this cookie expires, or is deleted.


Question: In which languages is the plugin available?

Answer: The plugin has 6 built-in languages: English, Greek, Spanish, German, Italian, and Swedish. If you would like to add a language, publish the translations by running:

And add/change your own translations. If you add a new language, consider also opening a pull request, in order for this language to be included in the plugin.


Question: Does this plugin work with all Laravel versions?

Answer: We have tested the plugin with Laravel 7, 8, and 9. The plugin's simplicity allows it to work with any Laravel version, but if you try it with a version other that the tested ones and it does not work, please open an issue on GitHub.


Question: If I install later a new cookie category, how can I force the plugin to "reset" and show again?

Answer: The easiest way is to publish the configuration file, and change the cookie_prefix field. This will force the plugin to show again.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for general details.

PHP code style - Laravel Pint

This application uses Laravel Pint in order to perform code-style.

In order to run the styler, run :

Releasing a new version

After you have committed your changes, create a new git tag:

(for the x.y.z version number, follow the Semantic Versioning guidelines).

Then, push the tag:

Then, in the GitHub Releases page, create a new Release and correlate it with the tag that you just created.**

That's it! Packagist will be updated automatically.

Also, don't forget to update the CHANGELOG.md file with the new version name, release date, and release notes.

Credits

License

The Apache Licence. Please see the Licence File for more information.


All versions of laravel-cookies-consent with dependencies

PHP Build Version
Package Version
Requires php Version ^8
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package scify/laravel-cookies-consent contains the following files

Loading the files please wait ....