Skip to content

Instantly share code, notes, and snippets.

@uberboom
Created September 22, 2015 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uberboom/812638c9854177147ec7 to your computer and use it in GitHub Desktop.
Save uberboom/812638c9854177147ec7 to your computer and use it in GitHub Desktop.
Laravel 5.1 Cross-Origin Resource Sharing (CORS) 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, X-Auth-Token, Origin');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment