Updating an Open Alert
Mutate the currently-open alert in place — no close/reopen, no flicker. Wraps SweetAlert2's Swal.update().
Fluent form
Chain setters, then call update() instead of show(). Open an alert first via the Loading page or any other call — then click Update.
LivewireAlert::title('Updated title')
->text('Body changed in place — no flicker.')
->update();
Explicit payload form
Pass a SweetAlert2 options array directly.
LivewireAlert::update([
'title' => 'Direct payload',
'icon' => 'success',
]);
Live progress
Combine asLoading() + wire:poll + update() for long-running work. Spinner stays, title rotates through phases.
public int $step = 0;
public bool $running = false;
protected array $phases = [
'Connecting...',
'Fetching data...',
'Crunching numbers...',
'Almost there...',
'Wrapping up...',
];
public function start(): void
{
$this->step = 0;
$this->running = true;
LivewireAlert::title($this->phases[0])
->asLoading()
->show();
}
public function tick(): void
{
if (!$this->running) return;
$this->step++;
if ($this->step >= count($this->phases)) {
$this->running = false;
LivewireAlert::close();
LivewireAlert::title('Done!')->success()->asToast()->show();
return;
}
LivewireAlert::title($this->phases[$this->step])->update();
}
<div>
<button wire:click="start">Start</button>
@if ($running)
<div wire:poll.800ms="tick"></div>
@endif
</div>
Real Laravel job batch
Drive update() from Bus::batch() state. Shown for reference — no live demo here since it requires a queue worker.
use Illuminate\Support\Facades\Bus;
public ?string $batchId = null;
public function start(): void
{
$batch = Bus::batch([
new \App\Jobs\ProcessRow(/* ... */),
new \App\Jobs\ProcessRow(/* ... */),
])
->name('row-import')
->allowFailures()
->dispatch();
$this->batchId = $batch->id;
LivewireAlert::title('Queued — waiting for workers...')
->asLoading()
->show();
}
public function tick(): void
{
if (!$this->batchId) return;
$batch = Bus::findBatch($this->batchId);
if (!$batch) {
$this->batchId = null;
LivewireAlert::close();
return;
}
if ($batch->finished()) {
$this->batchId = null;
LivewireAlert::close();
$batch->hasFailures()
? LivewireAlert::title("Finished with {$batch->failedJobs} failure(s)")->warning()->asToast()->show()
: LivewireAlert::title('Batch complete!')->success()->asToast()->show();
return;
}
LivewireAlert::title("Processed {$batch->processedJobs()} of {$batch->totalJobs}")
->update();
}
Use $batch->progress() (0–100) if you want a percent.
For push-driven updates, listen to batch events via Laravel Echo and call update() from a Livewire #[On(...)] listener — same API, no polling.
Swal.update() does not preserve input field values, fire didOpen, or rebind event handlers. It only swaps visual options. If no alert is currently visible, update() is a no-op (warning logged to console).