PHP code example of core45 / laravel-cookieconsent
1. Go to this page and download the library: Download core45/laravel-cookieconsent library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
core45 / laravel-cookieconsent example snippets
return [
// Passed through to CookieConsent.run() — see the configuration reference linked above.
'cookie' => [
'name' => 'cc_cookie',
'expiresAfterDays' => 182,
// WARNING: enabling `useLocalStorage` disables server-side consent
// reads (@consent, Consent::has(), consent:* middleware). See below.
],
'mode' => 'opt-in',
'revision' => 0,
'guiOptions' => [
'consentModal' => ['layout' => 'box', 'position' => 'bottom left'],
'preferencesModal' => ['layout' => 'box'],
],
'categories' => [
'necessary' => ['enabled' => true, 'readOnly' => true],
'analytics' => [
'autoClear' => [
'cookies' => [
// Use CookieConsent::regex('^_ga') for RegExp matching.
['name' => '_gid'],
],
],
],
],
// Package-only keys, stripped before the array reaches the JS config:
'translations_mode' => 'active', // 'active' = current locale only, 'all' = every published locale
'csp_nonce' => null, // see "Content Security Policy" below
'logging' => [ /* ... */ ], // see "Consent audit trail" below
'iframemanager' => [ /* ... */ ], // see "iframemanager" below
];
use Core45\CookieConsent\Facades\CookieConsent;
'autoClear' => [
'cookies' => [
['name' => CookieConsent::regex('^_ga')], // matches _ga, _ga_ABC123, ...
['name' => CookieConsent::regex('^_gid$', 'i')], // second arg is JS RegExp flags
],
],
use Core45\CookieConsent\Support\Consent;
use Core45\CookieConsent\Facades\CookieConsent;
app(Consent::class)->has('analytics'); // bool
CookieConsent::has('analytics'); // same, via the facade
CookieConsent::categories(); // list<string>, e.g. ['necessary', 'analytics']
CookieConsent::acceptType(); // 'all' | 'necessary' | 'custom' | null (no cookie yet)
'logging' => [
'enabled' => true,
'csrf' => true,
'capture_ip' => 'raw', // 'raw' | 'hashed' | false
'ip_hash_salt' => env('COOKIECONSENT_IP_SALT'),
'capture_user_agent' => true,
'link_user' => true,
'morph_id_type' => 'int', // 'int' | 'uuid' | 'ulid' | 'string' — must match your User key type
'policy_version' => null,
'retention_days' => null, // null disables pruning
'rate_limit' => '30,1', // Laravel throttle expression applied to the log endpoint
],
ConsentLog::forConsentId('abc123')->get();
ConsentLog::forUser($user)->get();
ConsentLog::between('2026-01-01', '2026-06-30 23:59:59')->get();
// or, with Carbon:
ConsentLog::between('2026-01-01', now()->parse('2026-06-30')->endOfDay())->get();
ConsentLog::latestPerConsentId()->get(); // one row per consent_id, the most recent