PHP code example of elhebert / laravel-croustillon

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

    

elhebert / laravel-croustillon example snippets


// app/Http/Kernel.php

...

protected $middlewareGroups = [
   'web' => [
       ...
       \Elhebert\Croustillon\Http\Middlewares\AddCookieBanner::class,
   ],

// in a routes file

Route::get('my-page', 'MyController')->middleware(Elhebert\Croustillon\Http\Middlewares\AddCookieBanner::class);

// in a policy

...
    ->addCookie(Xsrf::class)
    ->addCookie(Session::class)
...

namespace Elhebert\Croustillon\Cookies;

use Elhebert\Croustillon\Categories\Mandatory;

class Xsrf extends Cookie
{
    public $name = 'XSRF-TOKEN';

    public $category = Mandatory::class;

    public $source = 'Laravel';

    public $duration = '2 hours';

    public $purpose = 'security';
}

Elhebert\Croustillon\Categories\Mandatory::class
Elhebert\Croustillon\Categories\Preferences::class
Elhebert\Croustillon\Categories\Analytics::class
Elhebert\Croustillon\Categories\Social::class
Elhebert\Croustillon\Categories\Retargetting::class

public function duration(): string
{
    return config('session.lifetime') . ' minutes';
}

public function purpose(): string
{
    return trans('croustillon::cookies.purposes.security');
}

namespace App\Service\Croustillon\Policies;

use Elhebert\Croustillon\Policies\Basic;
use App\Service\Croustillon\Cookie\MyCustomCookie;

class MyCustomPolicy extends Basic
{
    public function configure()
    {
        parent::configure();

        $this
            ->addCookie(MyCustomCookie::class);
    }
}
bash
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-config"
bash
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-translations"
bash
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-views"
bash
php artisan vendor:publish --provider="Elhebert\Croustillon\CroustillonServiceProvider" --tag="croustillon-views"