From d90f017cbe5c7a86f800e8126e57dd3152465853 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 18 Jun 2023 18:41:14 +0300 Subject: [PATCH] Add the getItemIds in the Cart to get ids of items. --- app/Models/Cart.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index c591733..271e173 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -37,11 +37,18 @@ class Cart extends Model return $this->belongsToMany(Item::class, 'carts_items', 'cart_id', 'item_id'); } - public function isEmpty() { - return count($this->items()->pluck('item_id')->toArray()); + public function getItemIds(): array + { + return $this->items()->pluck('item_id')->toArray(); } - public function setCity(City $city) { + public function isEmpty() + { + return count($this->getItemIds()); + } + + public function setCity(City $city) + { if($this->city_id == $city->id) return;