Myat Htut
Myat Htut

Reputation: 487

ReflectionException Controller does not exist error in Lumen

I make Controller in App\Http\Controllers\Controller.php

I use route following code

$app->get('api/article','App\Http\Controllers\ArticleController@index');

But I can't call Controller! Controller does not exist..... error occur. How can solve? enter image description here

Upvotes: 0

Views: 6124

Answers (1)

Thomas Kim
Thomas Kim

Reputation: 15961

You only need to specify the namespace relative to App\Http\Controllers. So it would be like this:

$app->get('api/article','ArticleController@index');

Also, for future reference, if your controller is in a "deeper" namespace, the same rule applies. So, if your ArticlesController was in App\Http\Controllers\API\ArticleController, you would just need to do this:

$app->get('api/article', 'API\ArticleController@index');

It is very important to note that we did not need to specify the full controller namespace when defining the controller route. We only defined the portion of the class name that comes after the App\Http\Controllers namespace "root". By default, the bootstrap/app.php file will load the routes.php file within a route group containing the root controller namespace.

If you choose to nest or organize your controllers using PHP namespaces deeper into the App\Http\Controllers directory, simply use the specific class name relative to the App\Http\Controllers root namespace. So, if your full controller class is App\Http\Controllers\Photos\AdminController, you would register a route like so:

$app->get('foo', 'Photos\AdminController@method');

Source: http://lumen.laravel.com/docs/controllers#basic-controllers

Upvotes: 6

Related Questions