Ad

Route Names Inside A Group Prefix Does Not Include The Prefix

I have these routes:

Route::group(['middleware' => ['role:admin'], 'prefix' => 'admin'], function()
{
    Route::resource(__('route.events'), 'Auth\RoleAdmin\EventController');
});

Route::group(['middleware' => ['role:user'], 'prefix' => 'user'], function()
{
    Route::resource(__('route.events'), 'Auth\RoleUser\EventController');
});

I would expect the name of the resources routes start with admin. and user. respectively, but it does not happen.

This is the result of the command php artisan route:list:

|        | GET|HEAD      | auth/admin/events                                           | events.index                            | App\Http\Controllers\Auth\RoleAdmin\[email protected]                        | web,auth,role
:admin,guest,role:admin|user                        |
|        | POST          | auth/admin/events                                           | events.store                            | App\Http\Controllers\Auth\RoleAdmin\[email protected]                        | web,auth,role
:admin,guest,role:admin|user                        |
|        | GET|HEAD      | auth/admin/events/create                                    | events.create                           | App\Http\Controllers\Auth\RoleAdmin\[email protected]                       | web,auth,role
:admin,guest,role:admin|user                        |
|        | DELETE        | auth/admin/events/{events}                                  | events.destroy                          | App\Http\Controllers\Auth\RoleAdmin\[email protected]                      | web,auth,role
:admin,guest,role:admin|user                        |
|        | GET|HEAD      | auth/admin/events/{events}                                  | events.show                             | App\Http\Controllers\Auth\RoleAdmin\[email protected]                         | web,auth,role
:admin,guest,role:admin|user                        |
|        | PUT|PATCH     | auth/admin/events/{events}                                  | events.update                           | App\Http\Controllers\Auth\RoleAdmin\[email protected]                       | web,auth,role
:admin,guest,role:admin|user                        |
|        | GET|HEAD      | auth/admin/events/{events}/edit                             | events.edit                             | App\Http\Controllers\Auth\RoleAdmin\[email protected]                         | web,auth,role
:admin,guest,role:admin|user                        |

As you can see the routes of admin and routes of users have the same names, and the names don't include the prefix.

Ad

Answer

The kerbholz's solution is not working, but it helped me to solve.

Route::prefix('admin')
    ->middleware('role:admin')
    ->name('admin.') // <-- I had to add this line in order to work
    ->group(function() {
        Route::resource(__('route.events'), 'Auth\RoleAdmin\EventController');
});
Ad
source: stackoverflow.com
Ad