This package can secure any route in Laravel with a simple cookie.

v1.02 2019-06-18 16:04 UTC

This package is auto-updated.

Last update: 2024-05-19 02:53:29 UTC


COokie GUard for Laravel

Latest Version on Packagist Total Downloads

This package can secure any route in Laravel with a simple cookie. It will prevent anyone (or anything) to access a specific route if the cookie value you defined is not present on the request.


You can install the package via Composer:

composer require milhouse1337/cogul


To generate a random token (string) you can use openssl like this:

openssl rand -hex 32

Add the token on your .env file:


You can publish the config with (optional):

php artisan vendor:publish --provider="Milhouse1337\Cogul\CogulServiceProvider"

Here is an example config/cogul.php file:

return [
    'token'      => env('COGUL_TOKEN', ''),
    'url'        => env('COGUL_URL', '/auth/token/{token}'),
    'redirect'   => env('COGUL_REDIRECT', '/'),
    'cookie'     => env('COGUL_COOKIE', 'cogul'),
    'expiration' => env('COGUL_EXPIRATION', 2628000), // 5 years.
    'middleware' => env('COGUL_MIDDLEWARE', 'web'),
    'whitelist'  => [],


You have to define the routes you want to secure with the auth.cogul middleware, like this:

Route::get('example', 'Controller@example')->middleware('auth.cogul');

Now if you GET this /example you will have a 403 response from Laravel.

In order to get the expected response, you need to access the following link in your browser to set the cogul cookie:


The cookie should be stored in your browser and you will be redirected to the URL you configured.

You will now be able to access /example normally until the cookie gets expired or deleted.



The MIT License (MIT). Please see License File for more information.