Notification after redirect

I just went through the “Supporting Multiple Toaster Notifications At Once” video. Awesome stuff.

When an entity is created, I redirect from the create to the edit route. How can I show a notification, that the entity was created/saved?

I could flash a message on create:

session()->flash('notify', 'created');

Then in the component I could do:

if(session()->has('notify')) {
    $this->notify('...');
}

However this does not work, because there is no method in livewire that is executed after render, right?

How would you approach that problem?

Warm regards,
art

Hey, @artworkad

Use Events for this kind of tasks. See the docs for more information.

@skywalker from the docs, I am not sure how events would help. The redirect refreshes the entire page, the only way to say, that an entity was created, is through a flash message. Then e.g. in mount I can read the flash message but I cannot trigger the notification, because view is not rendered yet.

Any errors in the client side?

No errors. This is expected bahaviour. In mount I do

if(session()->has('notify')) {
  $this->notify('Created');
}

However the view is not rendered yet, so the notification cannot be displayed like in the “Supporting Multiple Toaster Notifications At Once” screencast.

Just noticed that my question is a dup of dispatchBrowserEvent on mount