Skip to content

Instantly share code, notes, and snippets.

View nkeena's full-sized avatar
🏠
Working from home

Neil Keena nkeena

🏠
Working from home
View GitHub Profile
@adamwathan
adamwathan / laravel-cors.php
Last active September 16, 2022 00:16
Need to do something like this to serve APIs that are going to be consumed by JS clients.
<?php
App::before(function($request) {
if ($request->getMethod() == 'OPTIONS') {
$response = Response::make('', 204);
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, OPTIONS');
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept, Authorization');
return $response;
}