I'm leaving reordering to front end (for example http://dbushell.github.io/Nestable/ ) and output is parsed by back end.
How do you handle with reordering items?
In my tables I often use field order to let users to manage order of their items. We can imagine some actions like creating new item, deleting old item, moving up item or moving it down. These actions affects on items order.
What parts of Laravel do you use to handle this situations? In my opinion it is good to use model's events like or creating or deleting.
For example when we delete t-shirt in products table we get https://s23.postimg.org/lmc79i4kr/table.png
How do you handle with reordering items? Do you use special libraries?
you are possibly overthinking it.
the only time you need to reorder is when the user specifically requests it...
adding a new item - put it at the end of the list. query the database and get the last item, get the sequence number, add one and save the new item as the next sequence
removing an item - just delete it. there will be a gap in the sequence number, but so what? Sorting the items ascending or descending will still work without sequential numbering.
reordering - accept a list of model ids and iterate through them giving the first 0, the next 1, 2, 3 etc. Pay no attention to what number they had before.
Please or to participate in this conversation.