stueynet's avatar

Route group with prefix, namespace and a route name

Trying to achieve a fairly specific thing here. I have an app with posts that are completely managed by the admin. So I am trying to put all of that behind a special admin area. I would like to have all the routes automatically prefixed as well as name those routes so I can easily change the admin url in future. So I have the following:

Route::group(['middleware' => ['web'], 'prefix' => 'm-a-d-m-i-n', 'namespace' => 'Admin'], function () {
    Route::resource('post', 'PostsController', ['as' => 'admin']);
});

However the named routes that get generated look like this because of the prefix:

 POST      | m-a-d-m-i-n/post                    | admin.m-a-d-m-i-n.post.store   | App\Http\Controllers\Admin\PostsController@store                      | web,auth   |
|        | GET|HEAD  | m-a-d-m-i-n/post                    | admin.m-a-d-m-i-n.post.index   | App\Http\Controllers\Admin\PostsController@index                      | web,auth   |
|        | GET|HEAD  | m-a-d-m-i-n/post/create             | admin.m-a-d-m-i-n.post.create  | App\Http\Controllers\Admin\PostsController@create                     | web,auth   |
|        | GET|HEAD  | m-a-d-m-i-n/post/{post}             | admin.m-a-d-m-i-n.post.show    | App\Http\Controllers\Admin\PostsController@show                       | web,auth   |
|        | DELETE    | m-a-d-m-i-n/post/{post}             | admin.m-a-d-m-i-n.post.destroy | App\Http\Controllers\Admin\PostsController@destroy                    | web,auth   |
|        | PUT|PATCH | m-a-d-m-i-n/post/{post}             | admin.m-a-d-m-i-n.post.update  | App\Http\Controllers\Admin\PostsController@update                     | web,auth   |

Thats not super helpful because I still need to reference the route name with the m-a-d-m-i-n. My ideal scenario would be as follows:

route uri: m-a-d-m-i-n/post/{post} 
route name admin.post.show 
route action: App\Http\Controllers\Admin\PostsController@show    

Looking forward to your responses!

0 likes
0 replies

Please or to participate in this conversation.