-
Notifications
You must be signed in to change notification settings - Fork 2
SweetToast
Viames Marino edited this page Mar 31, 2026
·
1 revision
Pair\Html\SweetToast generates JavaScript code for SweetAlert2 toast notifications.
new SweetToast(string $title, string $message, ?string $type = 'info')Valid types: info, success, warning, error, question, progress.
The API mirrors IziToast for easier driver switching:
balloon(bool $flag)class(string $class)close(bool $flag)closeOnEscape(bool $flag)displayMode(int $mode)icon(string $icon)id(string $id)image(string $image)position(string $position)progressBar(bool $flag)theme(string $theme)timeout(int|bool $timeout)overlay(bool $flag)render(): string
Unsupported iziToast-only options are kept as compatibility no-ops when SweetAlert2 does not offer an equivalent behavior.
Configure the driver once:
$app->setToastDriver('sweetalert');Then the standard helpers automatically emit SweetAlert2 toasts:
$this->toast('Saved', 'User updated', 'success');
$this->toastError('Error', 'Unable to save user');-
SweetToastrequires SweetAlert2 to be available in the page. - Custom icon class names are rendered through SweetAlert2
iconHtml. - When no position is provided,
SweetToastuses the native SweetAlert2 default position. -
position()accepts both iziToast-style values (topRight) and SweetAlert2 aliases (top-end,bottom-start).
See also: SweetAlert, IziToast, PairUI.js, Application.