2
votes

I have a resource controller placed inside a route group like so:

Route::group(['as' => 'admin.', 'prefix' => 'admin'], function () {
  Route::get('/', ['as' => 'index']);

  Route::patch('categories/{id}', ['uses' => 'controller@restore', 'as' => 'categories.restore']);
  Route::resource('categories', 'controller');
});

The first route is admin/ with route name admin.index as expected.
The 'extra' resource route is admin/categories/{id} with route name admin.categories.restore.
But the strange things happen when we check the route names for the resource controller.
The routes are as expected, ed. admin/categories/{categories} but the route names are al prefixed with admin.admin.

I know I can fix the problem by removing the as in the route group and prefixing the route names for the other resources inside the group except the resource controller, but I'd like to find a way how to fix this without editing my route group.

The added image is (part of) my route lists route list

1

1 Answers

0
votes

This comment on the laravel GitHub describes the issue perfectly.
What happend:
Pre , all resource controllers in a route group would first look for an as declaration, then for a prefix and would use both to define their name, e.g. as.prefix.resource.

This issue shows the clarification and changes made in Laravel 5.3 to prevent this behaviour. In its current form:

URL prefixes no longer affect the route names assigned to routes when using Route::resource, since this behavior defeated the entire purpose of using route names in the first place.