In this episode, we focus on setting up the form to add a new book to our application. We start by creating the necessary controller and route for displaying the form at /books/create
. Then, we scaffold the Blade view for our form inside a new books
folder, and hook up the navigation so it's easy to reach from the UI.
After getting the basic page structure in place, we jump into testing to make sure everything works as expected. We write a simple authentication test to verify that only logged-in users can access the book creation page. From there, we move on to building the actual form, borrowing some structure from the login page template.
We set up fields for 'title' and 'author', including displaying error messages for validation. An important detail is making sure the 'status' select dropdown is dynamically populated with all possible book statuses from our pivot class, and we write a test to confirm these options appear in the correct order.
Once the UI is sorted and the tests pass, we try submitting the form to confirm that a new book record gets created and saved to the database. Everything works nicely! Before wrapping up, we mention that in the next episode we'll focus on listing the books on the homepage and will use a cool Pest feature to streamline our tests for that. Stay tuned!