Skip to content

Instantly share code, notes, and snippets.

@MahdiMajidzadeh
Created February 21, 2017 09:06
Show Gist options
  • Save MahdiMajidzadeh/33ed8fc0a4ffe400a863bda599a3d855 to your computer and use it in GitHub Desktop.
Save MahdiMajidzadeh/33ed8fc0a4ffe400a863bda599a3d855 to your computer and use it in GitHub Desktop.
fix Access-Control-Allow-Origin in laravel
public function handle($request, Closure $next)
{
$domains = ['http://localhost:8080'];
if(isset($request->server()['HTTP_ORIGIN'])){
$origin = $request->server()['HTTP_ORIGIN'];
if(in_array($origin, $domains)){
header('Access-Control-Allow-Origin: '. $origin);
header('Access-Control-Allow-Headers: Origin, Content-type, Authorization');
}
}
return $next($request);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment