Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/route resource prefixing #4506

Closed

Conversation

cviebrock
Copy link
Contributor

Here's an example routing situation:

Route::group(['prefix' => 'admin'], function()
{
    Route::model('post', '\Package\Model\Post');
    Route::resource('post', '\Package\PostController', ['as'=>'package']);
});

And currently, here are the resulting routes from artisan routes:

+--------+---------------------------------+----------------------------+---------------------------------+
| Domain | URI                             | Name                       | Action                          |
+--------+---------------------------------+----------------------------+---------------------------------+
|        | GET|HEAD admin/post             | package.admin.post.index   | \Package\PostController@index   |
|        | GET|HEAD admin/post/create      | package.admin.post.create  | \Package\PostController@create  |
|        | POST admin/post                 | package.admin.post.store   | \Package\PostController@store   |
|        | GET|HEAD admin/post/{post}      | package.admin.post.show    | \Package\PostController@show    |
|        | GET|HEAD admin/post/{post}/edit | package.admin.post.edit    | \Package\PostController@edit    |
|        | PUT admin/post/{post}           | package.admin.post.update  | \Package\PostController@update  |
|        | PATCH admin/post/{post}         |                            | \Package\PostController@update  |
|        | DELETE admin/post/{post}        | package.admin.post.destroy | \Package\PostController@destroy |
+--------+---------------------------------+----------------------------+---------------------------------+

With this patch, if you set the as option on the Route::resource() call, it will assume that that string is what you want to prefix your route names with, and not any of the route group names that are currently being added. This would solve several other issues (e.g. #1616) and updates the way #3000 solved it.

While there might be some BC issues, I don't see them as truly major. If you are passing 'as' to your Route::resource(), then I don't think you'd be expecting any prefixes anyway.

In my case, this is for a package that supplies routes where the group prefix is configurable. And yes, I could use action based routing (as has always been suggested), but I think this fixes a general issue where routes aren't being named in a predictable way when you think they should be. :)

Another solution would be to allow something like a no_group_prefix option to be passed, in which case my code would change from:

-       if ($prefix || count($this->groupStack) == 0)
+       if (isset($options['no_group_prefix']) || count($this->groupStack) == 0)

@cviebrock
Copy link
Contributor Author

Oops ... PR to wrong branch. See #4507 instead.

@cviebrock cviebrock closed this May 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants