Where to Add CSRF Exception?

mattcdavis1 - 6 months ago

I see that there is a portion of code that provides addons access to middleware:

// Let addons manipulate middleware first.
foreach (app('Anomaly\Streams\Platform\Http\Middleware\MiddlewareCollection') as $middleware) {
    $this->middleware($middleware);
}

I'm just not sure how to go about implement this to add a csrf route exception. Can someone provide an example of adding an $except route to csrf middleware from a module?

dali - 6 months ago

I am also interested in this.. I ended up duplicating the construct of BaseController and remove the VerifyCsrfToken middleware for my Api Controllers

mattcdavis1 - 6 months ago

Yeah - i ended up with a similar approach in my controller:

public function middleware($middleware, array $options = [])
{
    $excluded = [
        'Illuminate\Foundation\Http\Middleware\VerifyCsrfToken',
    ];

    if (!in_array($middleware, $excluded)) {
        return parent::middleware($middleware, $options);
    }
}