connectholland/cookie-consent-bundle
Install via Composer:
composer require harborn-digital/cookie-consent-bundle
Publish the bundle's assets and configuration:
php artisan vendor:publish --provider="HarbornDigital\CookieConsentBundle\CookieConsentServiceProvider" --tag="config"
php artisan vendor:publish --provider="HarbornDigital\CookieConsentBundle\CookieConsentServiceProvider" --tag="public"
Add the bundle to config/app.php under providers if not auto-discovered.
First use case: Display the cookie consent banner by adding the Twig template to your layout:
{{ include('CookieConsentBundle::cookieConsent.html.twig') }}
config/cookie_consent.php (e.g., position, cookie_name, translations).use HarbornDigital\CookieConsentBundle\CookieConsentManager;
public function __construct(CookieConsentManager $cookieConsent)
{
$this->cookieConsent = $cookieConsent;
}
public function index()
{
if (!$this->cookieConsent->isConsentGiven()) {
return redirect()->route('home')->with('consent_required', true);
}
}
es) and Catalan (ca) locales by setting locale in config or via middleware:
$request->setLocale('es'); // Auto-switches translations
data-consent-accepted event listener for post-consent actions:
document.addEventListener('consentAccepted', (e) => {
// Load analytics, ads, etc.
});
public function handle($request, Closure $next)
{
if (!$this->cookieConsent->isConsentGiven()) {
abort(403, 'Consent required');
}
return $next($request);
}
Request directly. If you extended the bundle, update to use RequestStack (PR #125) to avoid Request not being available in some contexts (e.g., commands).php artisan vendor:publish --tag="public" --force
Then validate the published public/cookie-consent/ files.cookie_name in config isn’t conflicting with existing cookies. Use:
$this->cookieConsent->getCookieName(); // Debug current name
php artisan view:clear
php artisan config:clear
resources/views/vendor/cookie-consent/cookieConsent.html.twig.document.querySelector('.cookie-consent').style.position = 'fixed';
public function share(Request $request)
{
app()->setLocale($request->get('lang', config('app.locale')));
}
How can I help you explore Laravel packages today?