1

I'm currently working on a quite the large website in laravel 5.2 and i want to store the choice of languages inside a route middleware, this works as expected. But when i set a route controller inside the group the controller gets two variables instead of one. The language and the second variable to the controller as shown under. Is there any way to only pass one variable to the controller instead of two?

//Routing: 
Route::group(['prefix' => '{language}',  'middleware' => ['info']], function()
{

    Route::get("template/{template}", 'TemplateController@getTemplate');
}


//Example method in controller: 
public function getTemplate($language, $template)
{

    return response($template);
}

//What i want in the controller.  
public function getTemplate($template)
{

    return response($template);
}

1 Answer 1

2

Digging into the Illuminate\Routing\Route class:

/**
 * Unset a parameter on the route if it is set.
 *
 * @param  string  $name
 * @return void
 */
public function forgetParameter($name)

You can use forgetParameter to forget a parameter. You could call this from your language middleware.

$request->route()->forgetParameter('language');

Once forgotten the parameter won't be passed to the controller method, leaving only your template param to be passed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.