Cors en Laravel

martes, 6 de junio de 2017


Laravel 5.3
1. Crear un middleware
php artisan make:middleware Cors

2. Agregar headers al middleware (Http\Middleware\Cors.php)
public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin','*')
            ->header('Access-Control-Allow-Methods','GET, POST, PUT, DELETE, PATCH, OPTIONS')
            ->header('Access-Control-Allow-Headers','Content-Type, Authorization');
    }

3. Importar y agregar el middleware al Http\Kernel.php
protected $middleware = [
        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
        \App\Http\Middleware\Cors::class,
    ];

https://www.youtube.com/watch?v=84bXch-YIvI&list=PL55RiY5tL51rrgq6xi67Mc6cwOHXw_nB1&index=4

Librerías


Laravel 5
https://github.com/barryvdh/laravel-cors

Néstor Mercedes

Author & Editor

Has laoreet percipitur ad. Vide interesset in mei, no his legimus verterem. Et nostrum imperdiet appellantur usu, mnesarchum referrentur id vim.

0 comentarios:

Publicar un comentario