Skip to content

Routes with middleware (like auth) inside modulename-routes.php do not work #125

Description

@doraemonxxx

Hi,

internachi/modular v1.12.0

I’m currently using Laravel 8.75, where the RouteServiceProvider still exists. I noticed that when I add routes to a module’s route file (for example, app-modules/core/routes/core-routes.php) and group them with middleware such as auth, they don’t work as expected.

Example:

// app-modules/core/routes/core-routes.php
Route::group(['middleware' => 'auth'], function () {
    Route::get('/core', [CoreController::class, 'index']);
});

This route never gets recognized when accessed, but if I manually load the module route files from the RouteServiceProvider like this:

$modules_path = base_path('app-modules');
$modules = glob($modules_path . '/*', GLOB_ONLYDIR);

foreach ($modules as $module_path) {
    $routes_path = $module_path . '/routes';
    if (!is_dir($routes_path)) {
        continue;
    }

    foreach (glob($routes_path . '/*.php') as $route_file) {
        Route::middleware('web')
            ->namespace($this->namespace)
            ->group($route_file);
    }
}

then the routes (including those using auth middleware) start working properly.

So I’m wondering:

  • Is it necessary to manually add module route files (like modulename-routes.php) to the RouteServiceProvider for them to work?
  • Or should the package handle this automatically?
  • The documentation doesn’t seem to mention anything about middleware behavior in module routes, so I’m not sure if I’m missing a configuration step.

Thanks in advance for clarifying.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions