Skip to content

Commit

Permalink
Improve speed (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
driade authored and freekmurze committed Oct 19, 2016
1 parent fc71bf6 commit 9c7b173
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/SortableTrait.php
Expand Up @@ -53,11 +53,13 @@ public static function setNewOrder($ids, $startOrder = 1)
throw new SortableException('You must pass an array to setNewOrder');
}

$model = new static;

$orderColumnName = $model->determineOrderColumnName();
$primaryKeyColumn = $model->getKeyName();

foreach ($ids as $id) {
$model = static::find($id);
$orderColumnName = $model->determineOrderColumnName();
$model->$orderColumnName = $startOrder++;
$model->save();
static::where($primaryKeyColumn, $id)->update([$orderColumnName => $startOrder++]);
}
}

Expand Down

0 comments on commit 9c7b173

Please sign in to comment.