From 5b0a1ee8f6ace17009f0f16bda89520c2c7133a2 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Mon, 19 Jun 2023 21:55:48 +0300 Subject: [PATCH] Fix methods to add/remove items from the Cart. --- app/Models/Cart.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index e3b7c2e..ac0f885 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -107,24 +107,25 @@ class Cart extends Model $this->save(); } - public function addItemId(int $item) + public function addItemId(int $item_id) { - $this->items()->sync($item); + $this->addItemIds([$item_id]); } - public function addItemIds(array $items) + public function addItemIds(array $item_ids) { - $this->items()->sync($items); + $itemIDs = array_merge($this->getItemIds(), $item_ids); + $this->companies()->sync($itemIDs); } - public function removeItemId(int $item) + public function removeItemId(int $item_id) { - $this->items()->sync($item); + $this->items()->detach($item_id); } - public function removeItemIds(array $items) + public function removeItemIds(array $items_ids) { - $this->items()->sync($items); + $this->items()->detach($items_ids); } }