2017-03-15 42 views
2

對不起,奇怪的標題。我不是母語的人。 所以,這裏是我的routes/api.php內容:Laravel內核中間件組適用於路由,但不適用於分組路由

Route::post('login', 'Api\[email protected]'); 

Route::group([ 
    'prefix' => 'restricted', 
    'middleware' => 'auth:api', 
], function() { 
    // Authentication Routes... 
    Route::post('logout', 'Api\[email protected]'); 

    Route::get('user', 'Api\[email protected]'); 
}); 

正如你可能知道,這個文件中的每個路由具有默認的api前綴。在我Kernel.php我設置了一箇中間件api路線:

protected $middlewareGroups = [ 
    'web' => [ 
     ... 
    ], 

    'api' => [ 
     ..., 
     \Barryvdh\Cors\HandleCors::class, 
    ], 
]; 

現在我的問題是,當我打myapp/api/login從seprated應用(angular.js應用程序),它工作正常,但是當我嘗試獲取用戶來自myapp/api/restricted/user的數據我得到No 'Access-Control-Allow-Origin' header is present on the requested resource.錯誤。

我怎樣才能解決這個問題?

回答

0

問題出自getUser方法Api\Login Controller。我不知道爲什麼這會出現No 'Access-Control-Allow-Origin' header is present on the requested resource.錯誤,但我很高興它已修復。