In this episode, we walk through the full process of creating a new site in our Laravel/Inertia app using a modal form. We start by setting up the modal with Laravel Breeze components, like text inputs and buttons, to make building the UI as smooth as possible. You’ll see how to wire up form fields, use placeholders, and keep things accessible with screen-reader-only labels.
Once the frontend looks good, we dig into making it actually work: creating a new controller and POST route for handling form submissions, protecting it with middleware, and setting up a corresponding invokable controller method. We show how to hook up the frontend to the backend using Inertia's useForm
, letting you submit form data without a browser refresh.
From there, we handle splitting the entered URL into its scheme and domain, showing how to do that in a model observer before saving it to the database. We then test it all, making sure the data actually saves and that the UI updates without the user losing their place on the page—thanks to Inertia's preserve scroll feature.
You'll also see how to reset the form after submission and close the modal, so the user experience is tidy. Beyond the mechanics, we sprinkle in common best practices like form validation with Laravel Form Requests and displaying errors to users right in the modal using Inertia’s error handling. Extra touches include showing errors under the input and styling them so it’s clear when something is wrong.
By the end, you'll have a fully functional "add site" form with a slick modal, proper backend logic, validation, error display, and a seamless Inertia-powered frontend that just feels great to use.