user300285
user300285

Reputation:

Laravel group routing parameters with prefix

I've noticed that the parameters that you specify in a route prefix within a group are also supplied to all controllers that sit within that particular group which makes sense.

For example:

Route::group(array('prefix' => 'team/{id}/{slug}', 'before' => 'auth'), function () {
Route::get('documents/{document}', 'controllers\\team\\DocumentsController@show');
});

The DocumentsController's show method then has to follow the order of all parameters:

show($id, $slug, $document)

However, I don't really need the Team id and slug in the DocumentsController, they're just for pretty URLS. Is there anyway to pass only the parameters specified for that route to the DocumentsController (i.e. exclude the prefix params), as follows:

show($document)

Upvotes: 2

Views: 1553

Answers (1)

KernelCurry
KernelCurry

Reputation: 1297

You can parse the route pattern before it hits the controllers.

You would do this in the boot() method.

This is a very intricate problem to fix, but I can give you a little guidance. Take a look at 'Illuminate\Routing\Route' and there is a function setPattern() in the Route class you should look at.

Upvotes: 0

Related Questions