diff --git a/src/PositionObserver.php b/src/PositionObserver.php index 2af825e..2eb4023 100644 --- a/src/PositionObserver.php +++ b/src/PositionObserver.php @@ -45,7 +45,7 @@ public function saving($model) if ($model->isPositionUpdateDisabled() === false) { // Get the position for current and old value $position = $model->getPosition(); - + // Prevent modifying position column when updating and position columns has not changed if ($model->exists === true && $model->isDirty($model->getPositionColumn()) === false) { return; @@ -70,7 +70,7 @@ public function saving($model) * * @param Model|PositionTrait $model */ - public function deleting($model) + public function deleted($model) { if ($model->isPositionUpdateDisabled() === false) { // Get the old position diff --git a/src/Query/LastPositionQuery.php b/src/Query/LastPositionQuery.php index cb005f5..f275de2 100644 --- a/src/Query/LastPositionQuery.php +++ b/src/Query/LastPositionQuery.php @@ -41,6 +41,10 @@ public function runQuery($query) $lastPosition = $query->max($this->model()->getPositionColumn()) ?: 0; if (empty($this->oldPosition) === false) { + if ($this->oldPosition === $this->model->getPosition() && $lastPosition < $this->model->getPosition()) { + return; + } + (new MoveQuery($this->model, $lastPosition, $this->oldPosition))->run(); } else if ($this->oldPosition === null || $lastPosition != $this->oldPosition) { // Check if the last position is not same as original position - the same object