我正在为ecom网站开发Lumen REST API。突然我的应用崩溃了。我更新了我的作曲家和所有东西。但我找不到错误在哪里。但它仅在控制器文件中显示。
错误:
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
请帮帮我。
答案 0 :(得分:1)
如果没有看到你的路由定义只是那个错误,你看起来就是在路由中定义控制器的命名空间。流明自动假设您的所有控制器都驻留在App\Http\Controllers
。
我必须假设你这样做:
$app->get('myroute', ['as' => 'my.route', 'uses' => 'App\Http\Controllers\SubcatController']);
应该是:
$app->get('myroute', ['as' => 'my.route', 'uses' => 'SubcatController']);
答案 1 :(得分:1)
您的命名空间错误:
应用\ HTTP \控制器\应用\ HTTP \控制器\ SubcatController
确保您的控制器名称空间如下:
<?php
namespace App\Http\Controllers;
// ......
class SubcatController extends Controller
{
}
在您的路线文件中,您可以这样做:
Route::get('foo/bar', 'SubcatController@foo');
答案 2 :(得分:1)
检查你的/bootstrap/app.php。 有代码:
$app->group(['namespace' => 'App\Http\Controllers'], function ($app) {
require __DIR__.'/../app/Http/routes.php';
});
你的routes.php可能使用了命名空间&#39; App \ Http \ Controllers&#39;太。这是重复的。从routes.php中删除此命名空间
答案 3 :(得分:0)
$ app-&gt; get('myroute',['as'=&gt;'my.route','uses'=&gt;'SubcatController']);
先生。 Eric Tucker告诉这段代码它对我有用。
谢谢