Middleware for specific resources or pages
Is it possible to declare a middleware that only applies to certain resources or pages?
Solution:Jump to solution
So, I figured it out... you can add $routeMiddleware to Resources and Pages...
6 Replies
Why not,? The middleware has access to the request so you can do anything you want based on the path.
How would I call it? Filament automagically generates routes, so I can't declare it in the routes/web.php file
It’s just middleware. The path either contains a specified string or it doesn’t.
Sorry, I'm not providing enough context. I have a vendor middleware that I don't necessarily want to modify, but I want to call it on specific routes in my application.
I'm looking for a behavior similar to
Route::middleware(['vendormiddleware'])->group(function () {
**my routes**
});
It may not be best practice.... but you could do a check in the User model via a static method. Then just call it in the resource policy.
Yes yes yes... stop trowing food at me... but it works >_>
Solution
So, I figured it out... you can add $routeMiddleware to Resources and Pages...