Do you get any JS errors? Have you tried confirming that the event is called (i.e. adding an alert or console.log inside the init?) Here's how I would implement it.
1 Create a Bootstrap Toast in your HTML:
Firstly create an invisible Bootstrap Toast in your HTML (This is your toast template that will become visible upon triggering):
<div id="liveToast" class="toast" role="alert" aria-live="assertive" aria-atomic="true">
<div class="toast-header">
<strong class="me-auto">Bootstrap Toast</strong>
<button type="button" class="btn-close" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
<div class="toast-body">
Your Livewire component has been updated!
</div>
</div>
2 Set up an Alpine.js component in your blade file:
Just as before, create an Alpine.js component that listens to the 'open-toast' event:
<div x-data="{}" @open-toast.window="
var element = document.getElementById('liveToast');
var toast = new bootstrap.Toast(element);
toast.show();
"></div>
In the above example, the Alpine component is empty (x-data="{}"), and it simply exists to listen for the 'open-toast' event. This event triggers whenever we want to show the toast.
3 Listen to the 'updated' hook in your Livewire component: Again, you'd listen for the 'updated' hook event inside your Livewire component:
class YourComponent extends Component
{
protected $listeners = ['updated' => 'showToast'];
// ...
public function showToast($field)
{
$this->dispatchBrowserEvent('open-toast');
}
// ...
// Rest of your Livewire component
}
So, now whenever any livewire property updates, the 'updated' event fires, calling showToast method which dispatches a browser event called open-toast. This event is listened by the Alpine.js component that triggers the Bootstrap Toast defined earlier. This way you achieve showing the toast whenever a livewire property updates.