From 3fe7287e06358e23486c92349ee92361be32bc95 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 18 Jun 2023 18:42:40 +0300 Subject: [PATCH] Refactor the Cart model. Moved the dropItems above its first usage. --- app/Models/Cart.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index 271e173..fc21497 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -47,6 +47,10 @@ class Cart extends Model return count($this->getItemIds()); } + public function dropItems() { + $this->items()->detach(); + } + public function setCity(City $city) { if($this->city_id == $city->id) @@ -78,20 +82,19 @@ class Cart extends Model $this->items()->sync($item); } - public function addItems(array $items) { + public function addItems(array $items) + { $this->items()->sync($items); } - public function removeItem(BigInteger $item) { + public function removeItem(BigInteger $item) + { $this->items()->sync($item); } - public function removeItems(array $items) { + public function removeItems(array $items) + { $this->items()->sync($items); } - - public function dropItems() { - $this->items()->detach(); - } }