Skip to content

Instantly share code, notes, and snippets.

@sgorman
Last active September 22, 2016 14:41
Show Gist options
  • Select an option

  • Save sgorman/c402d183741c5e0634139f5781a75ad2 to your computer and use it in GitHub Desktop.

Select an option

Save sgorman/c402d183741c5e0634139f5781a75ad2 to your computer and use it in GitHub Desktop.
Laravel 5.3 CORS Middleware
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class CORS {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next, $origin='*')
{
$response = $next($request);
$response->headers->add([
'Access-Control-Allow-Origin' => $origin,
'Access-Control-Allow-Methods' => 'POST, GET, OPTIONS, PUT, DELETE',
'Access-Control-Allow-Headers' => 'Content-Type, Accept, Authorization, X-Requested-With'
]);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment