Larry AI does not seem to have read the Laravel 11 instructions. There's no Kernel.php in Laravel 11. :-/
Laravel 11 Middleware: Can I still do $this->middleware()->only([]) ?
I am all love for Laravel 11, except for the middleware part. Until now, I could define my Middleware, register it in the Kernel and then simply say:
$this->middlware('my-middleware')->only(['create', 'store', 'edit', 'update'])
But that no longer seems to be the case. What's the best way to achieve the above functionality without having to assign the middleware to each individual route?
you mean to use that in controller? if so, check this: https://laravel.com/docs/11.x/controllers#controller-middleware
just implement HasMiddleware in the controller and add a static middleware method, where you can specify your only/except actions:
public static function middleware(): array
{
return [
'auth',
new Middleware('log', only: ['index']),
new Middleware('subscribed', except: ['store']),
];
}
(example from the documentation mentioned above)
Please or to participate in this conversation.