Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Controllers can't be found inside a route group #239

Closed
geocine opened this issue Sep 3, 2015 · 9 comments
Closed

Controllers can't be found inside a route group #239

geocine opened this issue Sep 3, 2015 · 9 comments

Comments

@geocine
Copy link

geocine commented Sep 3, 2015

Eg. This will throw an error Class ServicesController does not exist

$app->group(['prefix' => 'v1' ], function ($app) {
    $app->get('/delete','ServicesController@remove');
});

To be able to fix this I must explicitly define the namespace

$app->group(['prefix' => 'v1' , 'namespace' => 'App\Http\Controllers'], function ($app) {
    $app->get('/delete','ServicesController@remove');
});

This should not be the case because this is already defined by default on the bootstrap\app.php

$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
    require __DIR__.'/../app/Http/routes.php';
});
@GrahamCampbell
Copy link
Member

Yeh, groups don't inherit in lumen, so you need to define the namespace over and over inside nested groups.

@jonvargas
Copy link

Won't this be fixed?

@IanNorris
Copy link

I also ran into this. It is not intuitive that this is the case and feels like a bug. At very least the documentation needs to be updated to mention this (if it is already mentioned, it needs mentioning again on the routes page). It is especially confusing as the namespace is set in app.php, so it isn't obvious that routes.php is actually already within a group unless you've dived a bit deeper into how things work.

@bogdanghervan
Copy link

I also feel that this needs to be better documented.

This example here suggests that namespaces are inherited and a developer should "register controller routes without specifying the full App\Http\Controllers namespace prefix.", but this is not the case (at least) with the default namespace group in bootstrap/app.php.

I'm defining an additional group in routes.php for routes that should get the auth middleware. I could apply the middleware to the default namespace group in bootstrap/app.php, but that would mean all routes will require authentication and I was hoping to define that more down the road in routes.php.

@pashamesh
Copy link

@bogdanghervan +1

1 similar comment
@jonwurtzler
Copy link

@bogdanghervan +1

@najib00
Copy link

najib00 commented Mar 8, 2016

@bogdanghervan +1
so the documentation not in sync with codes. here i thought that my env is broken.

@gokigoks
Copy link

What's the resolution for this? its become unintuitive

@matt-allan
Copy link
Contributor

@geocine looks like this was fixed, can you close this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants