I am trying to get collection from my local database (order)table and store it to online database (order) table. Basically what I am doing now is
- get all the order table data from local database and send it as order variable to blade
- send back order variable to online database using ajax
- store the order variable to online database (order) table
This last point (3) is where I am having an issue.
Here is how I get the data from the local database:
$orders = DB::table("orders")->where('created_at', '>', Carbon::now()->subHours(15))->latest()->get()->toArray();
return $orders;
And this is the order variable I get on the blade:
[{"id":11,"drinkName":"Power Horse","drinkId":"19","drinkType":"Energy Drink","costPerDrink":"5000","totalOrdered":"8","totalOrderAmount":"40000","discount":null,"transactionId":null,"status":"Initiated","waitressName":"Jane","waitressId":"3","created_at":"2024-08-27 14:52:56","updated_at":"2024-08-27 14:52:56"},id":10,"drinkName":"Coke","drinkId":"9","drinkType":"Chasers","costPerDrink":"1000","totalOrdered":"3","totalOrderAmount":"3000","discount":null,"transactionId":null,"status":"Initiated","waitressName":"Jane","waitressId":"3","created_at":"2024-08-27 14:52:49","updated_at":"2024-08-27 14:52:49"},{"id":9,"drinkName":"Crystal","drinkId":"1","drinkType":"Champagne","costPerDrink":"800000","totalOrdered":"3","totalOrderAmount":"2400000","discount":null,"transactionId":null,"status":"Initiated","waitressName":"Jane","waitressId":"3","created_at":"2024-08-27 14:52:41","updated_at":"2024-08-27 14:52:41"}]
This is how I send it to the online server:
function oneSecondFunction(){
$.ajax({
type:'POST',
url:"mysite/app/api/testItem",
data:{orders : orders, _token: "<?php echo csrf_token(); ?>" },
success:function(data){
console.log(data);
}
});
}
What I get at the online server:
[{"id":11,"drinkName":"Power Horse","drinkId":"19","drinkType":"Energy Drink","costPerDrink":"5000","totalOrdered":"8","totalOrderAmount":"40000","discount":null,"transactionId":null,"status":"Initiated","waitressName":"Jane","waitressId":"3","created_at":"2024-08-27 14:52:56","updated_at":"2024-08-27 14:52:56"},{"id":10,"drinkName":"Coke","drinkId":"9","drinkType":"Chasers","costPerDrink":"1000","totalOrdered":"3","totalOrderAmount":"3000","discount":null,"transactionId":null,"status":"Initiated","waitressName":"Jane","waitressId":"3","created_at":"2024-08-27 14:52:49","updated_at":"2024-08-27 14:52:49"},{"id":9,"drinkName":"Crystal","drinkId":"1","drinkType":"Champagne","costPerDrink":"800000","totalOrdered":"3","totalOrderAmount":"2400000","discount":null,"transactionId":null,"status":"Initiated","waitressName":"Jane","waitressId":"3","created_at":"2024-08-27 14:52:41","updated_at":"2024-08-27 14:52:41"}]
How can I store this at the online order table? any code samples and guidance are welcomed.