vedmaque's avatar

Lumen route groups nesting not working

Even though documentation says, that it is working, it is not.

Documentation:

$app->group(['namespace' => 'Admin'], function() use ($app)
{
    // Controllers Within The "App\Http\Controllers\Admin" Namespace

    $app->group(['namespace' => 'User'], function() use ($app) {
        // Controllers Within The "App\Http\Controllers\Admin\User" Namespace
    });
});

Making something similar:

$app->group(['namespace' => 'Info'], function() use ($app) {
    $app->group(['namespace' => 'Admin'], function() use ($app) {
        $app->get('info', 'InfoController@info');
    });
});

... and it says Class Admin\InfoController does not exist.

File structure with namespaces:

-Controllers
--Controller.php
--Info
---Admin
----InfoController.php

And contents of InfoController.php:

<?php
namespace App\Http\Controllers\Info\Admin;

use \App\Http\Controllers\Controller as Controller;

class InfoController extends Controller
{
    public function info()
    {
        return 'info 3';
    }
}

ps. actually, it ignores App\Http\Controllers, but it is not a problem.

0 likes
2 replies
paulredmond's avatar

@vedmaque did you open an issue on Github?

I haven't debugged this issue heavily, but in the meantime this will work too:

$app->group(['namespace' => 'App\Http\Controllers\Info'], function() use ($app) {
    $app->group(['namespace' => 'App\Http\Controllers\Info\Admin'], function() use ($app) {
        $app->get('info', 'InfoController@info');
    });
});
priti's avatar

What could be the the possible reason when one route is working and all other route start throwing 404 or 405. would be great if you can share how you are debugging the route. I tried adding Log::debug but no luck

Please or to participate in this conversation.