I am trying to get the return ($orders_box) of a function in my controller into my blade file javascript so that I can display it on a table on my blade file.
Right now the blade code looks like this:
function checkOrderId () {
const orderID = document.getElementById('PolarisTextField2').value;
const response = localStorage.getItem('orders_box');
fetch('/checkBalanceRoute/' + orderID)
.then(response => console.log(response))
}
and the controller code looks like:
{
public function checkBalance ($orderID){
$shop = Auth::user();
$req = $shop->api()->rest('GET', "/admin/api/2022-04/orders/$orderID.json");
$orders = $req['body']['orders'];
$orders_box = [];
foreach ($orders as $order) {
$data = array(
'Order Id' => $order->id,
'Total Price' => $order->total_price,
'Name' => $order->billing_address->name,
);
array_push($orders_box, $data);
}
return response() ->json([
'success' => true,
'order_box' => $orders_box
], 200);
}
Any thoughts?
I appreciate the help.