2

I'm using the Lumen fraemwork, a microframework by Laravel. The documentation is pretty similar, and I wanted to use Route groups. You can see it's documentation here

The problem I'm having, is, when using route groups, that Laravel tells me I'm having a ReflectionException when I want to call a Controller.

I wanted to build a route, to display all pages from my database. I did it with this route, which works

$app->get('/pages', 'PageController@index');

Now, I also wanted to let users make post/delete requests to the PageController. Since this would be modifying, I wanted to create a route group, with an api prefix, so all requests, which are POST or DELETE must be made via /api/pages

I did it like this

$app->group(['prefix' => '/api'], function($app){
});

Now, to test if this works generally, I added the get route from above into this group

$app->group(['prefix' => '/api'], function($app){
    $app->get('/pages', 'PageController@index');
});

But here, I'm getting the Errror

ReflectionException in Container.php line 736: Class PageController does not exist

Stacktrace

in Container.php line 736
at ReflectionClass->__construct('PageController') in Container.php line 736
at Container->build('PageController', array()) in Container.php line 626
at Container->make('PageController', array()) in Application.php line 393
at Application->make('PageController') in Application.php line 1259
at Application->callControllerAction(array(true, array('uses' => 'PageController@index'), array())) in Application.php line 1232
at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'PageController@index'), array())) in Application.php line 1217
at Application->handleFoundRoute(array(true, array('uses' => 'PageController@index'), array())) in Application.php line 1138
at Application->Laravel\Lumen\{closure}() in Application.php line 1370
at Application->sendThroughPipeline(array(), object(Closure)) in Application.php line 1144
at Application->dispatch(object(Request)) in Application.php line 1084
at Application->run(object(Request)) in index.php line 30

I didn't know if there was something wrong with my routes, or with the framework, so I added this simple route to the group

$app->group(['prefix' => '/api'], function($app){
    $app->get('/pages', function(){
        print 'test';
    });
});

When now calling the api/pages Endpoint, I'm getting the output. My document says test. So it seems there is something else wrong. What could it be?

Musterknabe
  • 5,763
  • 14
  • 61
  • 117
  • 2
    The accepted answer here hopefully answers your question: http://stackoverflow.com/questions/29692745/lumen-framework-routing-not-working – Joel Hinz Jul 15 '15 at 09:43
  • This works. But why do I have to do this only for route groups, and not for normal routes? – Musterknabe Jul 15 '15 at 09:48
  • 1
    I'm guessing it's because the get calls in the group are placed in a closure, which has no knowledge about the namespace. – Joel Hinz Jul 15 '15 at 10:37
  • Thanks! If you want, post it somehow as answer, I'll accept it. I solved it now, that I only put the grouped resources into the namespace groupo – Musterknabe Jul 15 '15 at 10:56
  • 1
    Thank you, I appreciate it, but I can't take credit for Lukas's answer. :) – Joel Hinz Jul 15 '15 at 11:55

0 Answers0