Created
October 23, 2020 21:05
-
-
Save nicholascourage/eb2da1f18f86d6c033cb1d6c25b4a684 to your computer and use it in GitHub Desktop.
This file contains 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
// 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