Skip to content

Instantly share code, notes, and snippets.

@fhferreira
Last active April 30, 2023 16:49
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save fhferreira/dfcd5c56dd9599abf75b to your computer and use it in GitHub Desktop.
Save fhferreira/dfcd5c56dd9599abf75b to your computer and use it in GitHub Desktop.
Try to create - Cors Filter Laravel 5 Middleware
<?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');
}
}
@tamarica
Copy link

where to locate this file?

@vlio20
Copy link

vlio20 commented May 19, 2015

+1

@marcobax
Copy link

marcobax commented Sep 9, 2015

@benjaminkohl
Copy link

I've tried this example and the OPTIONS request works but it still says the Access-Control-Allow-Origin header is not set.

@starter69
Copy link

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment