How to add a name prefix to all routes in a group?

October 26, 2018

You can use Route Name Prefixes. If you wanted to have a group of Laravel routes all with names like 'admin.users', '', etc then you can use a route name prefix to prepend 'admin.' to the start of all of the names

Route::name('admin.')->group(function () {
    Route::get('users', function () {
         })->name('users'); // Route will have the name "admin.users"...

However I do not like doing this, as it means I can't easily search for a particular route. But it does have the advantage of enforcing all in a group to have the same naming structure.