2016-11-09 84 views
0

我正在爲ecom網站開發流明REST API。突然我的應用程序崩潰。我已經更新了我的作曲家和所有東西。但是我找不到錯誤在哪裏。但它只在控制器文件中顯示。流明5.3路由不工作

錯誤:

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\[email protected]'), array())) in RoutesRequests.php line 647 
7. at Application->callActionOnArrayBasedRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\[email protected]'), array())) in RoutesRequests.php line 632 
8. at Application->handleFoundRoute(array(true, array('uses' => 'App\Http\Controllers\App\Http\Controllers\[email protected]'), 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 

請幫助我。

回答

1

你的命名空間是錯誤的:

應用程序\ HTTP \控制器\軟件\的Http \控制器\ SubcatController

確保您的控制器命名空間,如:

<?php 
namespace App\Http\Controllers; 

// ...... 

class SubcatController extends Controller 
{ 

} 

在你的路由文件,你可以這樣做:

Route::get('foo/bar', '[email protected]'); 
+0

這只是樣品,但我得到這個錯誤 –

+0

是的,我知道,但檢查錯誤信息。 – schellingerht

+0

好的,我會努力 –

1

沒有看到你的路由定義只是出現這個錯誤,它看起來像你正在定義的路由器中的控制器的命名空間。 Lumen自動假設您的所有控制器都駐留在App\Http\Controllers中。

我必須假設你正在做的:

$app->get('myroute', ['as' => 'my.route', 'uses' => 'App\Http\Controllers\SubcatController']); 

當它應該是:

$app->get('myroute', ['as' => 'my.route', 'uses' => 'SubcatController']); 
+0

我已經使用集團APP在這裏面路由器,所以我會如何編寫代碼 –

+0

如果該組中定義的命名空間,然後刪除它,該組內定義到控制器的路徑@method作爲'$ APP-> GET( 'myroute', 'SubcatController @的MyMethod')' –

0

$ APP-> GET( 'myroute',[ '作爲'=> 'my.route', '使用' =>'SubcatController']);

Eric Tucker先生告訴我這個代碼。

謝謝

1

檢查你的/bootstrap/app.php。 有代碼:

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

可能是你使用的routes.php文件命名空間 '應用程序\ HTTP \控制器' 太多。它是重複的。從您的routes.php文件中刪除此命名空間