My Approach
You may separate you routes
file in another file. Check RouteServiceProvider
class. In map
method, add another line:
public function map(Router $router)
{
$this->mapWebRoutes($router);
$this->mapNoMiddlewareRoutes($router);
}
Then add mapNoMiddlewareRoutes
method:
protected function mapNoMiddlewareRoutes(Router $router)
{
$router->group([
'namespace' => $this->namespace,
], function ($router) {
require app_path('Http/no_middleware_routes.php');
});
}
}
Finally, add no_middleware_routes.php
file within app/Http
folder.
Route::get('/foo', function () {
return ['foo' => 'bar'];
});
2nd Approach
Based on this article, you can use except
attribute.
protected $except = [
'webhook/*'
];
As you can see from the example, you can utilize wildcards for route matching or define each one individually. Internally, this array is ran through $request->is and you can find more details about that in the requests documentation.
Read more at CSRF Protection documentation