How to pass parameters to middleware #104
Unanswered
KamilSawicki
asked this question in
Q&A
Replies: 1 comment
-
|
You can use the same notation as with the standard Basically, use a #[Patch('your-path/{yourModel}', middleware: "yourmiddleware:argument1,argument2,yourModel,...")]so, in your case, simply: #[Patch('your-path/{yourModel}', middleware: "yourmiddleware:MyFancyRole")]assuming that you want to pass a The protected $routeMiddleware = [
// ...
'yourmiddleware' => \App\Http\Middleware\YourMiddleware::class,
// ...
];Currently, the documentation is a bit vague on it, providing only the It wouldn't hurt, if the #[Put('/post/{post}', middleware: "can:update,post")]as an equivalent of Laravel's example: use App\Models\Post;
Route::put('/post/{post}', function (Post $post) {
// The current user may update the post...
})->middleware('can:update,post'); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi. How can I use middleware with parameters? For example, I have middleware handle(Request $request, Closure $next, string $role) and I cannot find how to pass role parameter value.
Beta Was this translation helpful? Give feedback.
All reactions