In this episode, we work on updating the order of our links after they've been sorted in the front-end. We start by making sure we can pass an array of sorted IDs from Alpine.js over to our Livewire component in Laravel. To do this, we create an updateOrder
method in Livewire and hook it up so that it's triggered when the sort event happens.
After confirming that we're receiving the data correctly (using some good old dd()
debugging!), we use the power of our sortable package. With just one line, we set the new order for our links using the IDs passed in. It's super satisfying to see it working — items switch positions in the database, and the next time you refresh, they stay right where you moved them!
We also briefly mention a security concern: right now, any link could be reordered, not just the user's own links. We'll fix that in the next episode to make sure users can't mess with each other's data.