Middleware for specific resources or pages

Is it possible to declare a middleware that only applies to certain resources or pages?
Solution:
So, I figured it out... you can add $routeMiddleware to Resources and Pages...
public static array|string $routeMiddleware = ['specialmiddleware'];
public static array|string $routeMiddleware = ['specialmiddleware'];
Jump to solution
6 Replies
awcodes
awcodes8mo ago
Why not,? The middleware has access to the request so you can do anything you want based on the path.
Defenestrația
Defenestrația8mo ago
How would I call it? Filament automagically generates routes, so I can't declare it in the routes/web.php file
awcodes
awcodes8mo ago
It’s just middleware. The path either contains a specified string or it doesn’t.
Defenestrația
Defenestrația8mo ago
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** });
403gtfo
403gtfo8mo ago
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 >_>
No description
Solution
Defenestrația
Defenestrația8mo ago
So, I figured it out... you can add $routeMiddleware to Resources and Pages...
public static array|string $routeMiddleware = ['specialmiddleware'];
public static array|string $routeMiddleware = ['specialmiddleware'];
Want results from more Discord servers?
Add your server
More Posts