https://github.com/code16/cookie-consent
https://github.com/code16/cookie-consent
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/code16/cookie-consent
- Owner: code16
- Created: 2020-02-18T09:30:18.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-04-15T14:07:57.000Z (about 1 year ago)
- Last Synced: 2025-05-06T03:05:42.481Z (about 2 months ago)
- Language: PHP
- Size: 1010 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Cookie consent
## Setup
```bash
composer require code16/cookie-consent
```**Required**: publish assets (add this in composer.json `post-autoload-dump` scripts)
```php
php artisan vendor:publish --provider='Code16\CookieConsent\CookieConsentServiceProvider' --tag=assets --force
```You may publish the config file:
```php
php artisan vendor:publish --provider="Code16\CookieConsent\CookieConsentServiceProvider" --tag=config
```And the lang file:
```php
php artisan vendor:publish --provider="Code16\CookieConsent\CookieConsentServiceProvider" --tag=lang
```## Usage
### Default
In your blade layout
```blade{{-- ... --}}
@cookies
{{-- some injected cookies --}}
@endcookies{{-- end of the body --}}
@include('cookieConsent::index')```
### With category
To let the user manage multiple cookie categories (e.g. analytics, socials)
Add the category key to the `@cookies` directive
```blade{{-- ... --}}
@cookies('analytics')
{{-- some analytics script --}}
@endcookies```
Also you must declare the cookie category in `config/cookie-consent.php` as follow
```php
[
'cookie_categories' => [
'system' => [
'required' => true,
],
'analytics' => [],
]
];
```Categories marked as `required` are cannot be opt-out by the user.
To provide explanation texts in the manage dialog, add content to the lang file:
```php
[
'manage' => [
'title' => 'Manage cookies',
'description' => 'About cookies...',
'categories' => [
'system' => [
'title' => 'System cookies',
'description' => "Description text about system cookies",
],
'analytics' => [
'title' => 'Analytics cookies',
'description' => "Description text about analytics cookies",
],
],
]
];
```### Show the manage modal from a link (e.g. cookies page)
In the page:
```blade
@section('content')
Open manage cookies modal
@endsection
```### Intercept accept POST request
If you need to add some custom logic when cookies are accepted (meaning: either when the used clicked on OK in the Bar or after setting his choices on the Modal), you can define a Middleware in the cookie-consent-middleware config key, which will be executed on the POST request.Example:
```php
// in config/cookie-consent.php
return [
// ...
'middleware' => 'cookie-consent.accepted'
];
```