Laravel Routing: Route Groups
Route Groups
Allow you to share route attributes, such as middleware or namespaces, across a large number of routes without needing to define those attributes on each individual route.
Another common use-case for route groups is assigning the same PHP namespace to a group of controllers using the namespace method.
Middleware
Route::middleware(['first', 'second'])->group(function () {
Route::get('/', function () {
// Uses first & second Middleware
});
Route::get('user/profile', function () {
// Uses first & second Middleware
});
}); Middleware are executed in the order they are listed in the array.
Namespaces
Sub-Domain Routing
Route::domain('{account}.myapp.com')->group(function () {
Route::get('user/{id}', function ($account, $id) {
//
});
}); The sub-domain may be specified by calling the domain method before defining the group.
Sub-domains may be assigned route parameters just like route URIs, allowing you to capture a portion of the sub-domain for usage in your route or controller.
Semantic portal