When you write Restful API and you have a table that must be sort dynamically you can’t do that without Frontend.
If you have many columns you can’t get all columns and can’t do that.
if you want to use custom column name for position, set $sortableField: Now you can move your entities with methods moveBefore($entity) and moveAfter($entity) (you dont need to save model after that, it has saved already): Also this trait automatically defines entity position on the create event, so you do not need to add position manually, just create entities as usual: This entity will be at position entitiesMaximumPosition + 1
Something like:You need rutorika-sortable >=2.3 to use ->next() if you want group entity ordering by field, add to your model now moving and ordering will be encapsulated by this field.
Add \Rutorika\Sortable\BelongsToSortedManyTrait to your Post model and define belongsToSortedMany relation provided by this trait: Note: $this->belongsToSortedMany has different signature then $this->belongsToMany -- the second argument for this method is $orderColumn ('position' by default), next arguments are the same