Skip to content

Instantly share code, notes, and snippets.

@0xnbk
Last active October 3, 2015 02:27
Show Gist options
  • Save 0xnbk/b155bd939a0bcc745756 to your computer and use it in GitHub Desktop.
Save 0xnbk/b155bd939a0bcc745756 to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Middleware;
use Closure;
/**
* Class Cors
* @package App\Http\Middleware
*/
class Cors
{
/**
* Handle an incoming request.
*
* Please add header('Access-Control-Allow-Origin: http://example.com');
* & header('Access-Control-Allow-Credentials: true');
* at the top of your route file.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if ($request->isMethod('options')) {
return response('', 200)
->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
->header('Access-Control-Allow-Headers', 'accept, content-type,
x-xsrf-token, x-csrf-token'); // Add any required headers here
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment