Skip to content

Instantly share code, notes, and snippets.

@wilcorrea
Forked from geekcom/EnableCors.php
Created July 20, 2017 18:29
Show Gist options
  • Save wilcorrea/13fa2cb25c79e695dfb5a1477535ad8d to your computer and use it in GitHub Desktop.
Save wilcorrea/13fa2cb25c79e695dfb5a1477535ad8d to your computer and use it in GitHub Desktop.
Enable Cors Middleware
<?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');
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application');
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment