I am building an order management system in Laravel 5.3. I am storing the orders in two different tables - orders, order_content. The first one contains order's main data, the other - content. I am using Crinsane's Shopping Cart package for managing order contents. The order contents table fields: identifier, instance, content. Content field contains collection with the specific order content, which is searialized.
I add each order's content in collection and then pass that collection to view. My problem is I dont know how to access the collection's items in view... Controller:
public function showByDate()
{
$datetime_today = new DateTime('now');
$date = $datetime_today->format('Y-m-d');
/* $orders = Pasutijums::where('pasutijums_uz', '=', $date)
->where('ir_apstiprinats', '=', 1)->get(); */
$collection = collect();
foreach($orders as $order)
{
$order_contents = DB::table('order_content')->where('instance', '=', $order->pasut_num)->get();
foreach($order_contents as $content)
{
$collection->push(unserialize($content->content));
}
}
$items = $collection->all();
return view('admin.kopsavilkumi.pec-datuma')
->with('orders', $orders)
->with('date', $date)
->with('items', $items)
;
}
When I dd($collection) I get:
Collection {#292 ▼
#items: array:2 [▼
0 => Collection {#307 ▼
#items: array:2 [▼
"da951a56dc871db7b48a41f7d14b007b" => CartItem {#308 ▼
+rowId: "da951a56dc871db7b48a41f7d14b007b"
+id: "22"
+qty: "1"
+name: "Preces nosaukums 1"
+price: 7.5
+options: CartItemOptions {#309 ▶}
-associatedModel: null
-taxRate: 0
+"priceTax": 7.5
}
"138ba08bdbf1ac8f17e9e6f257af1b88" => CartItem {#310 ▼
+rowId: "138ba08bdbf1ac8f17e9e6f257af1b88"
+id: "123"
+qty: "1"
+name: "Preces nosaukums 2"
+price: 1.8
+options: CartItemOptions {#311 ▶}
-associatedModel: null
-taxRate: 0
}
]
}
1 => Collection {#306 ▼
#items: array:1 [▼
"da951a56dc871db7b48a41f7d14b007b" => CartItem {#312 ▼
+rowId: "da951a56dc871db7b48a41f7d14b007b"
+id: "22"
+qty: "1"
+name: "Preces nosaukums 3"
+price: 7.5
+options: CartItemOptions {#314 ▶}
-associatedModel: null
-taxRate: 0
}
]
}
]
}
View:
@foreach($items as $item)
@foreach($item as $order)
<tr>
<td class="text-primary"> </td>
<td> </td>
<td> </td>
</tr>
@endforeach
@endforeach
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire