From 6bb99c7f705136f1f065119009300ac9f1f60274 Mon Sep 17 00:00:00 2001 From: KKlochko Date: Mon, 19 Jun 2023 18:13:35 +0300 Subject: [PATCH] Add the clone method for Item model. --- app/Models/Item.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Models/Item.php b/app/Models/Item.php index f4e5bee..1ad194c 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -34,6 +34,15 @@ class Item extends Model $this->save(); } + public function clone($count = 1): Item + { + $copyItem = $this->replicate(); + + $copyItem->setCount($count); + + return $copyItem; + } + public function category(): BelongsTo { return $this->belongsTo(Category::class);