0
嗨,我正在Laravel 5.4工作。我用json_encode將我的購物車保存到數據庫,這是沒有問題的。我的問題是獲取我想要的數據。我想舉例說明產品的標題和價格。JSON解碼 - 解碼購物車PHP
我想:
@foreach ($order->cart->items as $item)
{{ dd(json_decode($order->cart, true)) }}
{{ $item['price']['title'] }}
@endforeach
這是當我得到了一個錯誤:
Trying to get property of non-object
當我傾倒我的購物車
dd(json_decode($order->cart, true))
我得到:
array:3 [▼
"items" => array:1 [▼
5 => array:4 [▼
"id" => 5
"qty" => 1
"price" => 15
"item" => array:8 [▼
"id" => 5
"created_at" => "2017-06-05 13:21:45"
"updated_at" => "2017-06-05 13:21:45"
"imagePath" => "https://someImage"
"title" => "Vitamin B-12"
"discription" => "Vitamin B-12, also called cobalamin ▶"
"category" => 4
"price" => 15
]
]
]
"totalQty" => 1
"totalPrice" => 15
]
'$項目[ 「項目」] [5] [ 「價格」] [ 「標題」]'是你數組的結構在這裏。 – apokryfos
它不是'$ order-> cart-> items'它的'$ order-> cart-> items()',項目是一個函數 –
@apOKRYFOS同樣的錯誤.. – Mette