In this episode, we tackle the issue of orderable items (like cards and columns) having global sequencing across different groups, instead of being locally ordered within their own boards or columns. You might've noticed that when you create cards, their order continues counting up even when you move them across different columns, which isn't what we usually want.
To fix this, we use the Eloquent Sortable package, but with a twist—we implement scoped ordering. First, we reset our boards and columns to get a clean slate. Then, in both the column and card models, we customize the order queries so that ordering gets scoped to their parent (columns get ordered per board, and cards get ordered per column). This way, each card or column list starts from 1, 2, 3...
We walk through updating the models to include a buildSortQuery
method which ensures sorting only applies within the specific parent group. After setting this up, you'll see that when you add or move cards between columns, their orders reset within their new column (e.g., cards show as 1, 2 in both Column 1 and Column 2). The same goes for columns—each board’s columns are ordered locally, which tidies things up in the database.
So by the end, you’ll have clean, scoped ordering for both cards and columns, which makes displaying them and managing them in your app much easier!