From 6c13fe7d7ddde8f607b56c2398e8aa714c3267ec Mon Sep 17 00:00:00 2001 From: KKlochko Date: Thu, 22 Jun 2023 10:58:21 +0300 Subject: [PATCH] Add the method to get cart items as the JSON array. --- app/Models/Cart.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index e005c23..0163326 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -56,6 +56,20 @@ class Cart extends Model return $item; } + public function getItemJSON() + { + $items = $this->items; + $itemJSON = []; + + foreach($items as $item) + array_push($itemJSON, [ + 'id' =>$item->uuid, + 'count'=> $item->count + ]); + + return $itemJSON; + } + public function getItemIds(): array { return $this->items()->pluck('item_id')->toArray();