A module route file returns a closure that receives the route builder.
return function ($route) {
$route->get('/', 'HomeController', 'index')->name('home');
$route->get('posts/[id=:num]', 'PostController', 'show')
->middlewares(['Auth'])
->cacheable(true, 300);
};use App\Modules\Admin\Controllers\ReportController;
return function ($route) {
$route->get('reports', ReportController::class, 'index');
};Short controller names are resolved inside the current module's Controllers namespace.
Use a fully-qualified class when you want a route file to point at a controller outside that default module path.
Apply group-wide middleware, rate limits, or caching by chaining after group(...):
$route->group('auth', function ($route) {
$route->get('login', 'AuthController', 'showLogin');
$route->post('login', 'AuthController', 'login');
})->middlewares(['Guest'])
->rateLimit(10, 60);$route->group('account', function ($route) {
$route->get('profile', 'AccountController', 'profile');
$route->post('avatar', 'AccountController', 'avatar')
->middlewares(['VerifiedUser']);
})->middlewares(['Auth']);In this pattern:
Authapplies to every route in theaccountgroupVerifiedUserapplies only toavatar
$route->get('orders/[id=:num]', 'OrderController', 'show');
$route->get('invite/[code=:alpha:8]', 'InviteController', 'show');
$route->get('search/[term=:any]?', 'SearchController', 'index');Read matched values through route_params() or route_param('name').
$route->get('health', function () {
return response()->json(['ok' => true]);
});Return a Response instance from closure handlers and controller actions.
Router creates controller instances directly for each dispatch, then resolves action arguments through the DI container. That keeps controllers lightweight and lets you receive matched params or services in the action itself.
use Quantum\Http\Request;
use Quantum\Http\Response;
class ProfileController
{
protected bool $csrfVerification = true;
public function update(Request $request, string $id): Response
{
return response()->json([
'updated' => true,
'id' => $id,
]);
}
}Route matching is first-match-wins.
[post1=:num] is invalid. Use [post=:num].
Use })->middlewares([...]) / ->rateLimit(...) / ->cacheable(...) for predictable group-wide behavior.