PHP code example of justijndepover / laravel-cookie-consent
1. Go to this page and download the library: Download justijndepover/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/ */
justijndepover / laravel-cookie-consent example snippets
use Justijndepover\CookieConsent\Concerns\InteractsWithCookies; // add this line
class Cookie
{
use InteractsWithCookies; // add this line
}
return [
/*
* Use this setting to enable the cookie consent dialog.
*/
'enabled' => env('COOKIE_CONSENT_ENABLED', true),
/*
* The name of the cookie in which we store if the user
* has agreed to accept the conditions.
*/
'cookie_name' => 'laravel_cookie_consent',
/*
* Set the cookie duration in days. Default is 365 * 20.
*/
'cookie_lifetime' => 365 * 20,
/*
* Set the model class that represents the cookies table
* Make sure your Cookie model implements the InteractsWithCookies trait
*/
'cookie_class' => \App\Models\Cookie::class,
/*
* These middleware will get attached onto each Laravel Cookie Consent route, giving you
* the chance to add your own middleware to this list or change any of
* the existing middleware. Or, you can simply stick with this list.
*/
'middleware' => ['web'],
];
sh
php artisan vendor:publish --tag="laravel-cookie-consent-migration"
php artisan migrate
sh
php artisan vendor:publish --tag="laravel-cookie-consent-config"
blade
@foreach ($cookies as $cookie) <!-- get the cookies from database -->
<form action="{{ route('cookies.toggle', ['cookie' => $cookie]) }}" method="POST">
@csrf
@if ($cookie->isEnabled())
<button type="submit" class="bg-green-200 text-green-600 text-xs rounded-full px-2 py-1">Active</button>
@else
<button type="submit" class="bg-red-200 text-red-600 text-xs rounded-full px-2 py-1">Not active</button>
@endif
</form>
@endforeach
sh
php artisan vendor:publish --tag="laravel-cookie-consent-view"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.