在 laravel 5.3 中启用 Cors

Enable Corrs in laravel 5.3

我尝试在 laravel 5.3 中启用 Cors。但它没有 运行.
我试过很多方法。
首先,我尝试包含中间件 Cors 并添加到 Kernel.php.

public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
    }
}

然后,我使用了插件 barryvdh/laravel-cors 但没有 运行。

希望有人指导或指正。

https://laravel.com/docs/5.4/middleware

上的示例

但是,此中间件将在应用程序处理请求后执行其任务:

<?php

namespace App\Http\Middleware;

use Closure;

class AfterMiddleware
{
    public function handle($request, Closure $next)
    {
        $response = $next($request);

        // Perform action

        $response->header('Access-Control-Allow-Origin', '*');

        return $response;
    }
}

简而言之:将其添加到response,而不是request