Created
July 2, 2018 13:51
-
-
Save AyozeVera/cfb431cf6f5370ce34cafe30adaae0c6 to your computer and use it in GitHub Desktop.
Laravel Cors Middleware configuration
This file contains 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 | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$response = $next($request); | |
if (method_exists($response, 'header')) { | |
$response | |
->header('Access-Control-Allow-Origin', '*') | |
->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Accept') | |
->header('Access-Control-Expose-Headers', 'X-Total-Count') | |
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS, PATCH'); | |
} | |
return $response; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment