In this episode, we're working on letting users add new endpoints from the UI and having them saved in the database. We start by creating a new controller, EndpointStoreController
, which is responsible for handling these new additions. Once that's set up, we also wire up the necessary route to make sure form submissions hit this controller.
On the frontend side, we hook up the add endpoint form to use Inertia's useForm
, initialize some default values, and make sure the frequency select input works nicely by defaulting to the first available frequency option. We handle form submission so that when the user adds an endpoint, the form posts the data and doesn't reload or scroll unnecessarily.
A key part here is making sure we're adding the endpoint for the right site, so we update our route and controller to make sure endpoints get associated with the correct site. Then, on the server-side, we set up the logic to save the endpoint with its location and frequency. As part of that, we also realize we need to automatically calculate the "next check" time for this new endpoint, so we set up an Observer to calculate it right before saving.
Finally, after confirming everything works—including default values, posting to the right place, the observer firing, and form resetting—we wrap it all up by making sure submissions reset the form and actually store the new endpoint data in the database. So, by the end of this episode, you can add endpoints, with the right frequency, all saved and ready for checks!