Skip to content

Commit

Permalink
optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaycalicut17 committed May 1, 2024
1 parent 050c594 commit d68d752
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
7 changes: 2 additions & 5 deletions src/Listeners/DeletedFromTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
4 changes: 2 additions & 2 deletions src/Listeners/RestoredFromTrash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
12 changes: 5 additions & 7 deletions src/Models/Trash.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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());

Check failure on line 62 in src/Models/Trash.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined static method Ajaycalicut17\LaravelTrash\Models\Trash::cursor().
}

/**
Expand Down

0 comments on commit d68d752

Please sign in to comment.