In this episode, we start putting the basics of notification flashing in place using Laravel and Inertia.js. First, we add a simple button to the dashboard page, which, when clicked, posts to a new route in our app. For demo purposes, we're just tossing this route in directly, but in a real project, you’d likely have a controller handling this. Either way, we return a success message to the user to confirm the action worked.
We set up the form to work with Inertia—meaning we import useForm
from Inertia, keep the form data empty, and post it to our new route when submitted. There's a neat aside about Ziggy, which bridges Laravel's named routes to the frontend, making routing super convenient in your JavaScript.
With the basics in place, we look at how information is shared globally in Inertia. Specifically, we use Laravel middleware to flash notification messages into the session, and then pick these up in the frontend. On the dashboard view, we pass the notification in as a prop and simply dump it onto the page when it’s available, seeing our success message after hitting the button.
But there’s a catch: our current approach isn’t very scalable or DRY. Handling notifications this way means more repetition and boilerplate than we’d like, especially as our app grows. The episode wraps up with a look ahead—teasing an improved way to pick up notifications automatically, without having to define props every time.
So for now, we’ve set up lame-but-functional notification flashing, and next, we’ll learn to make it way more elegant!