In this episode, we're tackling archiving for cards (and eventually columns) in our board app. First, we add an archived_at
column to our cards table, so each card can track if and when it got archived. We use a migration to set this up, allowing the value to be nullable so not every card is archived right away.
Next, we update the card model to handle casting archived_at
as a datetime, making it easy to work with. We then add a button in the card UI so users can archive a card. When archived, the card's archived_at
field gets set to the current timestamp, and the modal closes.
At this point, even though cards are archived in the database, they still show up on the board. This is because we need a way to fetch only the non-archived cards. We solve this by adding a notArchived
scope to the Eloquent model, so fetching cards ignores anything that's archived.
There's a bit of back and forth as we decide where this scope should go (card or column model), but ultimately it gets sorted out. Once in place, archived cards no longer appear on the board after a refresh.
But users want instant feedback! So we also update our Livewire components to immediately update the UI when a card is archived—no manual refresh needed. Events are emitted and listened for, ensuring the right columns update as soon as something is archived.
By the end of the episode, archiving a card hides it from view smoothly, both in the backend and on the page, making the feature feel polished and responsive.