Created
May 31, 2018 12:06
-
-
Save Scarwolf/89a4fa9ddd0683292d64812cb14e4a64 to your computer and use it in GitHub Desktop.
Laravel 5.6 CORS Middleware
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
// Full File Path: app/Http/Middleware/CORS.php | |
<?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); | |
$response->headers->set('Access-Control-Allow-Origin' , '*'); | |
$response->headers->set('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE'); | |
$response->headers->set('Access-Control-Allow-Headers', 'Content-Type, Accept, Authorization, X-Requested-With, Application'); | |
return $response; | |
} | |
} |
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
// Full File Path: app/Http/Kernel.php | |
protected $middleware = [ | |
[...] | |
\App\Http\Middleware\CORS::class | |
]; | |
protected $routeMiddleware = [ | |
[...] | |
'cors' => \App\Http\Middleware\CORS::class | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment