In this episode, we dive into building the UI and the backend functionality for adding columns to our kanban board. The process includes both some front-end Alpine.js work for toggling a form and some Livewire and PHP model work to actually persist the columns.
We start by placing an "Add Column" button right next to our list of columns. Then, we take some time to style that button, give it a nice plus icon, and make it visually consistent with the rest of the app. When you click the button, it flips over to show a form where you can type the name of the new column.
We discuss how to control the form’s visibility using Alpine.js – toggling between the button and the input form, handling focus so your cursor is ready in the field, and making sure canceling works smoothly.
On the backend, we cover setting up a form object in our Livewire component, validating the input, and actually creating the column in the database. We make sure to associate it with both the board and the current user. Along the way, we handle validation errors, “mass assignment” exceptions, and watch out for missing Eloquent relationships. Finally, we make sure that the UI resets itself after a successful column is added – the form hides again and the field is cleared.
By the end, you've got a polished and reactive “Add Column” feature that ties the front-end and back-end together seamlessly!