Skip to content

Laravel routing: Route in domain group visible also in local environment

What I need: My app has a public domain All routes in my Admin controller should be opened only if the remote domain is and also in local environment.

Currently: if I put the admin panel route in the group, it is not visible in local environment any more, making it difficult to develop.

// My secret domain, accessible only for admins

    Route::get('admin-panel', [AppHttpControllersControlAdminController::class, 'admin_panel']);


// To be accessible both in and
Route::get('homepage', [AppHttpControllersControlPagesController::class, 'homepage']);


My current solution: in route file web.php I add extra line

if( App::environment() == 'local') {
    Route::get('admin-panel', [AppHttpControllersControlAdminController::class, 'admin_panel']);

but it is a crude, temporary fix.


  • Either in route file or in the controller. A filter in a controller (for all or selected methods) would be best.
  • An if clause checking if either the environment is local or the domain is

Thank you.



I think laravel not support something like that. But you can declare the routes to a function variable and then use it in each domain.

$adminRoutes = function() {
    Route::get('admin-panel', [AppHttpControllersControlAdminController::class, 'admin_panel']);

Route::group(array('domain' => ''), $adminRoutes);
Route::group(array('domain' => 'localhost'), $adminRoutes)
User contributions licensed under: CC BY-SA
6 People found this is helpful