PHPackages                             digifactory/laravel-cookie-consent - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. digifactory/laravel-cookie-consent

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

digifactory/laravel-cookie-consent
==================================

Easily deal with cookie consent in your Laravel applications

v4.1.0(1y ago)915.0k↓35.7%1[1 issues](https://github.com/digifactory/laravel-cookie-consent/issues)[1 PRs](https://github.com/digifactory/laravel-cookie-consent/pulls)MITPHPPHP ^8.2CI passing

Since Feb 27Pushed 8mo ago4 watchersCompare

[ Source](https://github.com/digifactory/laravel-cookie-consent)[ Packagist](https://packagist.org/packages/digifactory/laravel-cookie-consent)[ Docs](https://github.com/digifactory/laravel-cookie-consent)[ RSS](/packages/digifactory-laravel-cookie-consent/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (9)Dependencies (4)Versions (13)Used By (0)

Laravel Cookie Consent
======================

[](#laravel-cookie-consent)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b504af25065fd161875be4193d5661ccc7e58225052ab27b7bad0454c5685760/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696769666163746f72792f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digifactory/laravel-cookie-consent)[![MIT Licensed](https://camo.githubusercontent.com/e8574c05e83bb056dea858d40b13f3f112991d90b33ee2a0c9e53aacf9afced6/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f64696769666163746f72792f6c61726176656c2d636f6f6b69652d636f6e73656e743f7374796c653d666c61742d737175617265)](LICENSE.md)[![run-tests](https://github.com/digifactory/laravel-cookie-consent/actions/workflows/run-php-tests.yml/badge.svg)](https://github.com/digifactory/laravel-cookie-consent/actions/workflows/run-php-tests.yml)[![Quality Score](https://camo.githubusercontent.com/0160af526518c08bb2ba1e8af265291ee4c3d2a1017ba89f635c21b78239e7e4/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f64696769666163746f72792f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/digifactory/laravel-cookie-consent)[![StyleCI](https://camo.githubusercontent.com/c1b7592f1983aa21d5f595a213db600ca53eec0b434f8698701140b952250f2d/68747470733a2f2f7374796c6563692e696f2f7265706f732f3234333238373336342f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/243287364)[![Total Downloads](https://camo.githubusercontent.com/ee40c360e5d83db0011f9f793e87569ffad47f05a0c81dae2d4aced5bafdcf1e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64696769666163746f72792f6c61726176656c2d636f6f6b69652d636f6e73656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/digifactory/laravel-cookie-consent)

This package makes dealing with cookie consent in your Laravel app and Blade views a piece of cake. By default the package uses [Cookiebot](https://manage.cookiebot.com/goto/signup?rid=R4INC) as its 'consent provider'. It doesn't replace the Cookiebot's (or any other consent provider's) JavaScript implementation. Laravel v6.5 is required, this is necessary for the `unless` Blade directive.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require digifactory/laravel-cookie-consent
```

You can publish the config file:

```
php artisan vendor:publish --provider="DigiFactory\CookieConsent\CookieConsentServiceProvider" --tag="config"
```

Usage
-----

[](#usage)

By default cookie consent is enabled. This means for all conditionals we use the consent provider to check if the user has given consent. You can disable cookie consent by creating an environment variable `COOKIE_CONSENT_ENABLED` and set it to `false`. If cookie consent is disabled all checks will return `true`, so all cookies are allowed as if the user has given consent for all types of cookies.

### Blade

[](#blade)

You can use the following Blade directives in your views:

- `cookieConsentNecessary`
- `unlesscookieConsentNecessary`
- `elsecookieConsentNecessary`
- `endcookieConsentNecessary`
- `cookieConsentPreferences`
- `unlesscookieConsentPreferences`
- `elsecookieConsentPreferences`
- `endcookieConsentPreferences`
- `cookieConsentStatistics`
- `unlesscookieConsentStatistics`
- `elsecookieConsentStatistics`
- `endcookieConsentStatistics`
- `cookieConsentMarketing`
- `unlesscookieConsentMarketing`
- `elsecookieConsentMarketing`
- `endcookieConsentMarketing`

You can do something like this:

```
@cookieConsentStatistics

@endcookieConsentStatistics

@cookieConsentMarketing

@else
    Please allow marketing cookies to view this video. Click here to renew or change your cookie consent.
@endcookieConsentMarketing

@unlesscookieConsentPreferences
    We cannot save your preferences because you did not allow preference cookies.
@endcookieConsentPreferences
```

### PHP

[](#php)

Or check for given consent in your PHP code:

```
CookieConsent::forNecessary();
CookieConsent::forPreferences();
CookieConsent::forStatistics();
CookieConsent::forMarketing();
```

If you don't want to use the Facade then you can use `app('cookie-consent')`:

```
app('cookie-consent')->forNecessary();
app('cookie-consent')->forPreferences();
app('cookie-consent')->forStatistics();
app('cookie-consent')->forMarketing();
```

### Implementing your own consent provider

[](#implementing-your-own-consent-provider)

You consent provider should implement the `ConsentProvider` contract:

```
