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 能通过跨域,下面的那个不行。

9c6ed2def27da171fa106e1fa1a4ca2c.png


Vote Vote Cancel Collect Collect Cancel

<< 上一篇: php框架 laravel 路由里面的 [user=>]是什么意思

>> 下一篇: 通过模型绑定获得数据以后怎么指定字段