Inspecting FlashMessages Component0:00
Next, I'd like to figure out how these flash messages work. If I switch to my editor, let's go back to Contacts, Create, yeah, there's no reference to a flash message here, which tells me it's probably in the layout.vue file. So let's go to layout.vue, and let's see, hmm, there it is. Okay, so here is the slot to which everything here will be, well, slotted, and then right above it, it looks like he has a component called FlashMessages. And that makes sense. So here's the slot, and right above it is the flash messaging. Okay, let's see what's going on there. First, it is a shared component that we are referencing here.
it. And then it looks like here's another one. If we have an error flash message, or we have errors at all. So if there is an error key flash message, or if there are validation errors, in either of those cases, we're going to display what you see here, which, of course, is this. So let's see, where is the content coming from? Okay, so if we have any errors at all, or I'm sorry, if we have exactly one error, this is just handling the pluralization. If we have exactly one error, then right, there's one error. So if we, you know, run this, there's one form error.
Tracing Session Flash Data3:06
I'm not sure. But either way, we you can see we're grabbing all values for success from the session and all values for error. So for example, if we go back to ContextController to see how to populate those, scrolling down and yeah, right here is where we flash data to the session. And again, notice the key matches up. If you had an error, then you would provide it there. And that would get thrown in the error flashback. Okay, so it sounds like if we come on back, let's see. So if we just load the page, and there is no flash data, let's go to view.
Handling Validation Error Display4:11
So that's why we see this generic, there are two form errors. Yeah, so that's what he's checking for here. If you have a specific flash message for that error bag, then we will display that. But otherwise, if this is just a case of failed validation, then we will spit out a generic response there. Okay, that's fairly simple. Nothing too crazy going on here. Makes perfect sense to me. So now I know a good way to deal with flash messaging, if I'm working with view, and I'm working with inertia, is to include it as part of my shared data there.
Sharing Flash Data in Inertia4:36
So now I know a good way to deal with flash messaging, if I'm working with view, and I'm working with Inertia, is to include it as part of my shared data there. Then if I want, I can create a component where I simply inspect that shared data and conditionally display it. Works for me.
