1

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

1 Answer 1

2

You can't replace abtest:0 middleware. Because, it had executed first. So you must change your route structure

Route::group(['prefix' => '/' . $languagePrefix, 'middleware' => ['sessionapi']], function () {
    Route::middleware('abtest:0')->group( function(){
            // all routes using abtest:0
    });

    Route::get('/i18n', [
        'as' => 'api:i18n',
    ])->middleware('abtest:1');


});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.