Skip to content

Instantly share code, notes, and snippets.

@nicholascourage
Created October 23, 2020 21:05
Show Gist options
  • Save nicholascourage/eb2da1f18f86d6c033cb1d6c25b4a684 to your computer and use it in GitHub Desktop.
Save nicholascourage/eb2da1f18f86d6c033cb1d6c25b4a684 to your computer and use it in GitHub Desktop.
// Middleware/Cors.php (run php artisan made:middleware Cors from app directory)
public function handle($request, Closure $next){
return $next($request)
->header('Access-Control-Allow-Origin', '*')
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
}
// Add to $routeMiddelware array in Kernel.php
'cors' => \App\Http\Middleware\Cors::class,
// use middleware in api routes/api.php
Route::group(['middleware' => 'cors'], function () {
//app routes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment