For answer seekers with Laravel 5.5+ finding this page:
Route::namespace('Admin')->prefix('admin')->name('admin.')->group(function () {
Route::resource('users','UserController');
});
These options will result in the following for the Resource:
namespace()
sets Controller namespace to \Admin\UserController
prefix()
sets request URi to /admin/users
name()
sets route name accessor to route('admin.users.index')
In name()
the DOT is intended, it is not a typo.
Please let others know if this works in comments for any versions prior to Laravel 5.5, I will update my answer.
Update:
Taylor accepted my PR to officially document this in 5.5:
https://laravel.com/docs/5.5/routing#route-group-name-prefixes
UPDATE LARAVEL 8
New in Laravel 8, the need to use a namespace
in route configs is deprecated, the default namespace
wrapper in RouteServiceProvider
has been removed from Laravel's standard config.
This change decouples Controller namespaces from having to be considered when grouping routes, dropping the namespace
requirement when registering routes gives much more freedom when organizing controllers and routes.
With Laravel 8, the original example in the top half of this post would now look as follows using self references to static class name:
use \App\Http\Controllers\Admin\{
UserController,
ProductController,
AnotherController,
}
Route::prefix('admin')->name('admin.')->group(function () {
Route::resource('users', UserController::class);
Route::resource('products', ProductController::class);
Route::resource('another', AnotherController::class);
});