Where the prefix will filter the news belonging to a certain category A, B, C, ..
I don't want to define a seperate route group for every category.
It should be something like Route::group(['prefix' => '{category}']
It would be handy if I can build the URL with named routes like this: route('news'), route('news', 1) . So without having to provide the prefix as a parameter. The app should read the current URL prefix to determine which prefix to use for the links.
Is there any way I can easily set this up in Laravel 5.3 or Laravel 5.4 ?
Or if not, are there packages out there that provide a middleware for this, and perhaps even some eloquent scopes to filter my models on the prefix?
It's also worth mentioning that when using resource controllers, you can skip the prefix from being injected into the methods signature (if your model requires this), by overwriting the callAction method in your controller :
public function callAction($method, $parameters) {
if (isset($parameters['category'])) {
unset($parameters['category']);
}
return parent::callAction($method, $parameters);
}