Skip to content

Instantly share code, notes, and snippets.

@AyozeVera
Created July 2, 2018 13:51
Show Gist options
  • Save AyozeVera/cfb431cf6f5370ce34cafe30adaae0c6 to your computer and use it in GitHub Desktop.
Save AyozeVera/cfb431cf6f5370ce34cafe30adaae0c6 to your computer and use it in GitHub Desktop.
Laravel Cors Middleware configuration
<?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