PHP code example of devrabiul / laravel-cookie-consent

1. Go to this page and download the library: Download devrabiul/laravel-cookie-consent 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/ */

    

devrabiul / laravel-cookie-consent example snippets


{!! CookieConsent::styles() !!}

{!! CookieConsent::scripts() !!}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Your Page</title>
    {!! CookieConsent::styles() !!}
</head>
<body>

    <!-- Your content -->
    
    {!! CookieConsent::scripts() !!}
</body>
</html>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Your Page</title>
    {!! CookieConsent::styles() !!}
</head>
<body>

    <!-- Your content -->
    
    {!! CookieConsent::scripts(options: [
        'cookie_lifetime' => config('laravel-cookie-consent.cookie_lifetime', 7),
        'reject_lifetime' => config('laravel-cookie-consent.reject_lifetime', 1),
        'disable_page_interaction' => config('laravel-cookie-consent.disable_page_interaction', true),
        'preferences_modal_enabled' => config('laravel-cookie-consent.preferences_modal_enabled', true),
        'consent_modal_layout' => config('laravel-cookie-consent.consent_modal_layout', 'bar-inline'),
        'flip_button' => config('laravel-cookie-consent.flip_button', true),
        'theme' => config('laravel-cookie-consent.theme', 'default'),
        'cookie_prefix' => config('laravel-cookie-consent.cookie_prefix', 'Laravel_App'),
        'policy_links' => config('laravel-cookie-consent.policy_links', [
            ['text' => CookieConsent::translate('Privacy Policy'), 'link' => url('privacy-policy')],
            ['text' => CookieConsent::translate('Terms & Conditions'), 'link' => url('terms-and-conditions')],
        ]),
        'cookie_categories' => config('laravel-cookie-consent.cookie_categories', [
            'necessary' => [
                'enabled' => true,
                'locked' => true,
                'js_action' => 'loadGoogleAnalytics',
                'title' => CookieConsent::translate('Essential Cookies'),
                'description' => CookieConsent::translate('These cookies are essential for the website to function properly.'),
            ],
            'analytics' => [
                'enabled' => env('COOKIE_CONSENT_ANALYTICS', false),
                'locked' => false,
                'title' => CookieConsent::translate('Analytics Cookies'),
                'description' => CookieConsent::translate('These cookies help us understand how visitors interact with our website.'),
            ],
            'marketing' => [
                'enabled' => env('COOKIE_CONSENT_MARKETING', false),
                'locked' => false,
                'js_action' => 'loadFacebookPixel',
                'title' => CookieConsent::translate('Marketing Cookies'),
                'description' => CookieConsent::translate('These cookies are used for advertising and tracking purposes.'),
            ],
            'preferences' => [
                'enabled' => env('COOKIE_CONSENT_PREFERENCES', false),
                'locked' => false,
                'js_action' => 'loadPreferencesFunc',
                'title' => CookieConsent::translate('Preferences Cookies'),
                'description' => CookieConsent::translate('These cookies allow the website to remember user preferences.'),
            ],
        ]),
        'cookie_title' => CookieConsent::translate('Cookie Disclaimer'),
        'cookie_description' => CookieConsent::translate('This website uses cookies to enhance your browsing experience, analyze site traffic, and personalize content. By continuing to use this site, you consent to our use of cookies.'),
        'cookie_modal_title' => CookieConsent::translate('Cookie Preferences'),
        'cookie_modal_intro' => CookieConsent::translate('You can customize your cookie preferences below.'),
        'cookie_accept_btn_text' => CookieConsent::translate('Accept All'),
        'cookie_reject_btn_text' => CookieConsent::translate('Reject All'),
        'cookie_preferences_btn_text' => CookieConsent::translate('Manage Preferences'),
        'cookie_preferences_save_text' => CookieConsent::translate('Save Preferences'),
    ]) !!}

</body>
</html>
bash
php artisan vendor:publish --provider="Devrabiul\CookieConsent\CookieConsentServiceProvider"