Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

thesimons's avatar

Registering new routes file

Hello,

in my web.php file I have currently the following block of code for admin.myapp.com. The number of entries is pretty low cause I started the project today:

Route::domain(config('domains.admin'))->group(function () {
    Route::middleware([AdminAuth::class])->group(function () {
        Route::get('/', [DashboardController::class, 'index'])->name('admin.dashboard');
    });
    Route::get('/login', [AdminLoginController::class, 'index'])->name('admin.login');
});

Since I know from now that the app will be quite big, I prefer to split the routes and put all admin related routes into a separated file admin.php.

Now I have to register the route. I simply wanted to register the route file admin.php with inside the block

Route::domain(config('domains.admin'))->group(function () {
});

But it looks like I can remove the domain condition and add it in the bootstrap/app.php.

Could you please clarify for me it a bit?

Thanks, Simon

0 likes
3 replies
thesimons's avatar

@Glukinho Yes, I read it. However I was a bit confused with the "domain" thing.

Anyway I fixed with:

then: function () {
            Route::middleware('web')
                ->domain(config('domains.admin'))
                ->group(function () {
                    require base_path('routes/admin.php');
                });
        },
Glukinho's avatar

@thesimons According to documentation, this would be enough:

->group(base_path('routes/admin.php'));

No need to have a closure with require inside.

Please or to participate in this conversation.