From 59bd4a1ddaad23671b1c5c24ef9c8a2d020d9ff1 Mon Sep 17 00:00:00 2001 From: Oskars Germovs Date: Fri, 22 Nov 2024 19:17:05 +0200 Subject: [PATCH] 1.) added: amend to sortables to array to avoid crashing 2.) added: bugfix to bootSortableTrait is not set if not used in model as fallback Signed-off-by: Oskars Germovs --- src/SortableTrait.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SortableTrait.php b/src/SortableTrait.php index b2d58ff..02542dc 100644 --- a/src/SortableTrait.php +++ b/src/SortableTrait.php @@ -14,24 +14,24 @@ trait SortableTrait { - public array|null $sortables; + public array $sortables = []; public static function bootSortableTrait(): void { static::creating(function (Model $model) { - if ($model instanceof Sortable && $model->shouldSortWhenCreating()) { + if (($model instanceof Sortable || $model instanceof Model) && $model->shouldSortWhenCreating()) { $model->setHighestOrderNumber(); } }); static::updating(function (Model $model): void { - if ($model instanceof Sortable && $model->shouldSortWhenUpdating() && !empty($model->sortables)) { + if (($model instanceof Sortable || $model instanceof Model) && $model->shouldSortWhenUpdating()) { self::setMassNewOrder($model->sortables); } }); static::deleting(function (Model $model): void { - if ($model instanceof Sortable && $model->shouldSortWhenDeleting() && !empty($model->sortables)) { + if (($model instanceof Sortable || $model instanceof Model) && $model->shouldSortWhenDeleting()) { self::setMassNewOrder($model->sortables); } });