# SweetAlert2 with Livewire

Install SweetAlert in master layout

On views that expect to use SweetAlert, or in master layout file, add a listener

```javascript
window.addEventListener('swal',function(e){ 
    Swal.fire(e.detail);
});
```

Then trigger an event from Livewire component when you want to show the popup

```php
$this->dispatchBrowserEvent('swal', ['title' => 'Feedback Saved']);
```

Pass any SweetAlert config elements to style your popup

```php
$this->dispatchBrowserEvent('swal', [
	'title' => 'Feedback Saved',
	'timer'=>3000,
	'icon'=>'success',
	'toast'=>true,
	'position'=>'top-right'
]);
```

{% embed url="<https://sweetalert2.github.io/#usage>" %}

You might instead use this package;

{% embed url="<https://github.com/jantinnerezo/livewire-alert>" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://talltips.novate.co.uk/livewire/sweetalert2-with-livewire.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
