Skip to content

Instantly share code, notes, and snippets.

@Signorini
Created July 16, 2015 19:51
Show Gist options
  • Save Signorini/39c5e5af1fb7dbdaeb1c to your computer and use it in GitHub Desktop.
Save Signorini/39c5e5af1fb7dbdaeb1c to your computer and use it in GitHub Desktop.
Middleware - Cors implemetation
<?php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Response;
class Cors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$config = config('cors');
if($request->getMethod() == "OPTIONS") {
$response = new Response();
foreach($config['options'] as $key => $value)
{
$response->headers->set($key, $value);
}
return $response;
}
$content = $next($request);
foreach($config['outhers'] as $key => $value)
{
$content->headers->set($key, $value);
}
return $content;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment