laravel 跨域
composer:
"barryvdh/laravel-cors": "^0.11.2",
Route:
Route::get('category/infos', function(\App\Models\Category $category, \App\Models\Info $info){ return $category::all()->each(function($item, $key) { $item->apiInfo->toArray(); }); }); Route::get('category/{category_id}', function(\App\Models\Info $info, $category_id){ return $info::where('category_id', $category_id)->paginate(15); });
VerifyCsrfToken:
protected $except = [ 'api/*', ];
Kernel:
protected $middlewareGroups = [ 'web' => [ \App\Http\Middleware\EncryptCookies::class, \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, \Illuminate\Session\Middleware\StartSession::class, // \Illuminate\Session\Middleware\AuthenticateSession::class, \Illuminate\View\Middleware\ShareErrorsFromSession::class, \App\Http\Middleware\VerifyCsrfToken::class, \Illuminate\Routing\Middleware\SubstituteBindings::class, ], 'api' => [ 'throttle:60,1', 'bindings', \Barryvdh\Cors\HandleCors::class ], ];
目前的情况是:Infos 能通过跨域,下面的那个不行。
2 Comments
这个问题已解决,
我也遇到这个问题了,请问你是怎么解决的呢?