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/ */
// 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';
}
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);
}
}