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.
錯誤。
我怎樣才能解決這個問題?