Skip to content

Toasts

The AlertManagerInterface provides a fluent and consistent way to display toast notifications using SweetAlert2 in Symfony applications.

Overview

Toasts are lightweight, non-blocking notifications that appear on the screen and automatically disappear after a given time. This implementation is fully integrated with Symfony sessions and flash messages.

Usage

Inject AlertManagerInterface into your controller or service and use the toast() method to create toast notifications:

use Pentiminax\UX\SweetAlert\AlertManagerInterface;
public function __construct(
private AlertManagerInterface $alertManager
) {}
public function someAction(): Response
{
$this->alertManager->toast(
title: 'Profile Updated!',
text: 'Your changes have been saved.',
timer: 3000,
timerProgressBar: true
);
return $this->redirectToRoute('profile');
}

Themes

Toasts share the same theme API as alerts:

use Pentiminax\UX\SweetAlert\Enum\Theme;
$toast = $this->alertManager->toast(title: 'Saved!');
$toast->theme(Theme::MaterialUILight);

Theme styles are not auto-imported (see assets/package.json autoimport entries).