Reputation: 8560
If I have middleware like:
<?php namespace App\Http\Middleware;
class SomeMiddleware
{
public function handle($request, Closure $next, $id = null)
{
//
}
}
In kernel.php:
'someMiddleware' => \App\Http\Middleware\SomeMiddleware::class,
In routes.php :
Route::put('post/{id}', ['middleware' => 'someMiddleware']);
How I can pass id captured in {id} to my middleware? I know that I can pass some custom parameter like this:
Route::put('post/{id}', ['middleware' => 'someMiddleware:16']);
But in laravel documentation there is no described how to pass argument captured in route pattern.
Upvotes: 3
Views: 1132
Reputation: 19275
I think that you can get the parameter from inside the middleware like this:
//your middleware's method
public function handle($request, Closure $next)
{
//get the ID
$id = $request->id
}
Upvotes: 1