Skip to main content

How do I add a route to the CSRF exception list?

If you do not want your route to require a valid CSRF token

Code

To add a route to the exceptions list through code you need to add to the static VerifyCsrfToken::$exceptionsarray.

<?php

namespace Acme\MyModule;

use Aero\Common\Providers\ModuleServiceProvider;
use Aero\Store\Http\Middleware\VerifyCsrfToken;

class ServiceProvider extends ModuleServiceProvider
{
   public function setup()
   {
       VerifyCsrfToken::$exceptions[] = '/my-route';
   }
}

Configuration

The routingconfiguration file has a csrf_exceptionsarray where you can list routes for the exceptions list.

You can publish the routingconfiguration file with this command:

php artisan vendor:publish --provider="Aero\Routing\Providers\RoutingServiceProvider"

Once this file is published you can view it by navigating to config/aero/routing.phpin your project. You can edit the csrf_exceptionsarray directly in this file.

You may need to clear the config cache for your changes to take effect.

php artisan config:clear