Skip to content

Instantly share code, notes, and snippets.

@protozoo
Forked from fhferreira/CORS.php
Last active August 29, 2015 14:24
Show Gist options
  • Save protozoo/dbabeab7499a585621a5 to your computer and use it in GitHub Desktop.
Save protozoo/dbabeab7499a585621a5 to your computer and use it in GitHub Desktop.
Laravel 5 Middleware to enable CORS requests #cors #crossdomain
<?php namespace App\Http\Middleware;
use Closure;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Http\Response;
class CORS implements Middleware {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
return $next($request)->header('Access-Control-Allow-Origin' , '*')
->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
->header('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment