Reputation: 365
I am developing Lumen REST API for ecom website. Suddenly my app crash. I have updated my composer and all stuff. But I can’t find where is the error. But its shows in controller file only.
Error :
ReflectionException in Container.php line 749:Class App\Http\Controllers\App\Http\Controllers\SubcatController does not exist
1. in Container.php line 749
2. at ReflectionClass->__construct('App\Http\Controllers\App\Http\Controllers\SubcatController') in Container.php line 749
3. at Container->build('App\Http\Controllers\App\Http\Controllers\SubcatController', array()) in Container.php line 644
4. at Container->make('App\Http\Controllers\App\Http\Controllers\SubcatController', array()) in Application.php line 211
5. at Application->make('App\Http\Controllers\App\Http\Controllers\SubcatController') in RoutesRequests.php line 680
6. at Application->callControllerAction(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\SubcatController@all'), array())) in RoutesRequests.php line 647
7. at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\SubcatController@all'), array())) in RoutesRequests.php line 632
8. at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\SubcatController@all'), array())) in RoutesRequests.php line 529
9. at Application->Laravel\Lumen\Concerns\{closure}(object(Request))
10. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
11. at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in ExampleMiddleware.php line 30
12. at ExampleMiddleware->handle(object(Request), object(Closure)) in Pipeline.php line 137
13. at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
14. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
15. at Pipeline->Laravel\Lumen\Routing\{closure}(object(Request)) in Pipeline.php line 104
16. at Pipeline->then(object(Closure)) in RoutesRequests.php line 782
17. at Application->sendThroughPipeline(array('App\Http\Middleware\ExampleMiddleware'), object(Closure)) in RoutesRequests.php line 535
18. at Application->dispatch(null) in RoutesRequests.php line 476
19. at Application->run() in index.php line 28
Please help me.
Upvotes: 0
Views: 1215
Reputation: 11
Check your /bootstrap/app.php. There is code:
$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
require __DIR__.'/../app/Http/routes.php';
});
Probably your routes.php used namespace 'App\Http\Controllers' too. It's duplicated. Remove this namespace from your routes.php
Upvotes: 1
Reputation: 365
$app->get('myroute', ['as' => 'my.route', 'uses' => 'SubcatController']);
Mr. Eric Tucker told this code it work for me.
Thanks
Upvotes: 0
Reputation: 5806
Your namespace is wrong:
App\Http\Controllers\App\Http\Controllers\SubcatController
Be sure your controller is namespaced like:
<?php
namespace App\Http\Controllers;
// ......
class SubcatController extends Controller
{
}
In your route file, you can do like this:
Route::get('foo/bar', 'SubcatController@foo');
Upvotes: 1
Reputation: 6345
Without seeing your route definition with just that error it looks like you are defining the namespace of the controller in the route. Lumen automatically assumes all your controllers reside in App\Http\Controllers
.
I have to assume you are doing this:
$app->get('myroute', ['as' => 'my.route', 'uses' => 'App\Http\Controllers\SubcatController']);
When it should be:
$app->get('myroute', ['as' => 'my.route', 'uses' => 'SubcatController']);
Upvotes: 1