Last active
October 3, 2015 02:27
-
-
Save 0xnbk/b155bd939a0bcc745756 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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