2
我想在頁面上顯示來自api調用的一些數據。數據是用於比特幣支付的。所以我有訂單,如果客戶用比特幣支付我想看到確認,金額等。獲取JSON數組並顯示來自該數組的結果
Here is one example url哪些返回json數據。
這裏就是我想在我的控制器
public function ordersView($orderId) {
/** @var Order $order */
$order = Order::where('order_id', $orderId)->first();
if (!$order) {
App::abort(404);
}
$url="http://btc.blockr.io/api/v1/tx/info/9585d5f635eddf737c8351bfe0879c3dbef3d94de9feda2bd74c990b06b7dc52";
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
$total = file_get_contents($url);
return View::make('site.admin.orders_view', [
'order' => $order,
'total' => $total
]);
}
,然後在視圖
@foreach($order->getOrderData($order->data) as $itemId => $item)
// some product info like name, description etc..
@foreach($total as $i => $totals)
{{ $totals['confirmations'] }}
{{ $totals['time_utc'] }}
@endforeach
@endforeach
當前的錯誤,我得到的是
'Invalid argument supplied for foreach()
在內部的foreach
@foreach($total as $i => $totals)
{{ $totals['confirmations'] }}
{{ $totals['time_utc'] }}
@endforeach
有人可以幫我解釋這些數據嗎?
感謝您的答案,但我仍然得到這個錯誤''爲foreach提供的foreach()'無效參數.. – Garg
我已經刪除了'foreach'循環並試圖直接訪問'$ total ['confirmations' ]'但是得到了'NULL' – Garg
我已經在我的本地嘗試了你的代碼,它的工作正常。 –