From 0c2f6355cfc45bc368feb341d23459dbd44f0476 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Sun, 18 Jun 2023 17:34:23 +0300 Subject: [PATCH] Add methods to add and remove Items from a Cart. --- app/Models/Cart.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/Models/Cart.php b/app/Models/Cart.php index f5cc164..b5ac2f1 100644 --- a/app/Models/Cart.php +++ b/app/Models/Cart.php @@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; use App\Models\City; +use Brick\Math\BigInteger; class Cart extends Model { @@ -51,6 +52,22 @@ class Cart extends Model $this->save(); } + public function addItem(BigInteger $item) { + $this->items()->sync($item); + } + + public function addItems(array $items) { + $this->items()->sync($items); + } + + public function removeItem(BigInteger $item) { + $this->items()->sync($item); + } + + public function removeItems(array $items) { + $this->items()->sync($items); + } + public function dropItems() { $this->items()->detach(); }