Skip to content

Instantly share code, notes, and snippets.

@danilodorgam
Created June 15, 2018 21:01
Show Gist options
  • Save danilodorgam/363dd15d2a3676e6161bca1b0d2417dd to your computer and use it in GitHub Desktop.
Save danilodorgam/363dd15d2a3676e6161bca1b0d2417dd to your computer and use it in GitHub Desktop.
Script para liberar acesso via API por outros domínio (Liberar o Cors)
//app/Http/Middleware/EnableCors.php
<?php
namespace App\Http\Middleware;
use Closure;
class EnableCors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$response = $next($request);
$response->headers->set('Access-Control-Allow-Origin', '*');
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE, PATCH');
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, origin, Accept, Authorization, X-Requested-With, Application');
return $response;
}
}
//Http/Kernel.php
<?php
...
protected $middleware = [
...
\App\Http\Middleware\EnableCors::class,
];
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment