I have a Route group which applies middlewares to all nested routes. I am passing a parameter to it.
Inside the group, though, I have a specific route for which I want to pass a different parameter. Which I do as following:
Route::group(['prefix' => '/' . $languagePrefix, 'middleware' => ['sessionapi', 'abtest:0']], function () {
// other routes
Route::get('/i18n', [
'as' => 'api:i18n',
])->middleware('abtest:1');
}
But in the middleware handle
itself, the parameter is always 0, the generic one, even if I visit the route with the different parameter.
How come?
public function handle($request, Closure $next, string $customPar = null)
{
// ...
dd($customPar); // always 0
// ...
}
I tried to use ->withoutMiddleware(['abtest'])->->middleware('abtest:1')
but it didn’t work
2
Answers
Remove the type-hinting(string) before the ‘$customPar = null’ parameter of the handle method.
Changed Code…
Give it a try..
You can’t be replace abtest:0 middleware. Because, it had executed first. So you must change your route structure