From d68d752ec22edea202d937450bd64685c89c9693 Mon Sep 17 00:00:00 2001 From: ajaycalicut17 Date: Wed, 1 May 2024 13:55:36 +0530 Subject: [PATCH] optimization --- src/Listeners/DeletedFromTrash.php | 7 ++----- src/Listeners/RestoredFromTrash.php | 4 ++-- src/Models/Trash.php | 12 +++++------- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/Listeners/DeletedFromTrash.php b/src/Listeners/DeletedFromTrash.php index a1830e1..23dc8ea 100644 --- a/src/Listeners/DeletedFromTrash.php +++ b/src/Listeners/DeletedFromTrash.php @@ -14,11 +14,8 @@ public function __construct() // } - /** - * Handle the event. - */ - public function handle(DeleteFromTrash $deleteFromTrash): void + public function handle(DeleteFromTrash $event): void { - $deleteFromTrash->model->trashable()->forceDelete(); + $event->model->trashable()->forceDelete(); } } diff --git a/src/Listeners/RestoredFromTrash.php b/src/Listeners/RestoredFromTrash.php index 992447d..47421e6 100644 --- a/src/Listeners/RestoredFromTrash.php +++ b/src/Listeners/RestoredFromTrash.php @@ -17,8 +17,8 @@ public function __construct() /** * Handle the event. */ - public function handle(RestoreFromTrash $restoreFromTrash): void + public function handle(RestoreFromTrash $event): void { - $restoreFromTrash->model->trashable()->restore(); + $event->model->trashable()->restore(); } } diff --git a/src/Models/Trash.php b/src/Models/Trash.php index 8f271a1..6520069 100644 --- a/src/Models/Trash.php +++ b/src/Models/Trash.php @@ -35,9 +35,9 @@ public function trashable(): MorphTo } /** - * restore associated model form trash. + * Restore the associated model from the trash. */ - public function restoreFromTrash(): Trash + public function restoreFromTrash(): self { $this->deleteQuietly(); @@ -55,13 +55,11 @@ public function deleteFromTrash(): ?bool } /** - * delete all trashed model and associated model. + * Delete all trashed models and their associated models. */ - public static function emptyTrash(): LazyCollection + public static function emptyTrash(): void { - return static::cursor()->each(function ($each) { - $each->delete(); - }); + static::cursor()->each(fn (Trash $trash) => $trash->delete()); } /**