Skip to content

In laravel 11 and 12, making new routes files and applying middleware and domain to them difficult or impossible? #55249

Answered by rodrigopedra
bhojkamal asked this question in Q&A
Discussion options

You must be logged in to vote

@bhojkamal you can have full control on route registration by passing a \Closure to the withRouting method:

<?php

use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Routing\Router;

return Application::configure(basePath: \dirname(__DIR__))
    ->withRouting(function (Application $app, Router $router) {
        $router->middleware('api')
            ->prefix('/api')
            ->as('api.')
            ->group($app->basePath('routes/api.php'));

        $router->middleware('web')
            ->group($app->basePath('routes/web.php'));
    })
    // in case you want to keep routes/con…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by crynobone
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #55198 on April 02, 2025 02:24.