Skip to content

ToastBuilder API ​

The ToastBuilder is a specialized builder for creating toast notifications. It automatically configures toast-specific defaults — toast: true, hidden confirm button, visible close button, top-end position, and a timer progress bar.

Import ​

php
use RealRashid\SweetAlert\Builders\ToastBuilder;

Creation ​

Toasts are typically created via the Alert facade:

php
Alert::toast('Message', 'success')->flash();

Or using the global helper:

php
toast('Message', 'success')->flash();

Default Configuration ​

The ToastBuilder applies these defaults on construction:

SettingDefaultSource
toasttrueHardcoded
position'top-end'config('sweetalert.toast.position')
showCloseButtontrueconfig('sweetalert.toast.show_close_button')
showConfirmButtonfalseconfig('sweetalert.toast.show_confirm_button')
timerProgressBartrueconfig('sweetalert.toast.timer_progress_bar')
timer5000config('sweetalert.toast.auto_close')

Factory Methods ​

MethodReturnDescription
make()staticCreate a new builder from the container
reset()staticReset to default configuration

Core Configuration ​

MethodParametersDescription
title(string $title)Toast messageSet the toast title/message
text(string $text)Description textSet the body text
icon(string|AlertType $type)Icon typeSet the toast icon
success()—Set icon to success
error()—Set icon to error
warning()—Set icon to warning
info()—Set icon to info
question()—Set icon to question

Flash & Serialize ​

MethodReturnDescription
flash(string $type = 'config')staticFlash to session
toArray()arrayGet filtered config
toJson()stringGet config as JSON
getConfig()arrayGet raw config array

Backward Compatibility ​

MethodDescription
middleware()Apply middleware toast settings and flash

Inherited Traits ​

ToastBuilder uses the same traits as AlertBuilder and inherits all their methods:

  • HasTimer: timer(), autoClose(), timerProgressBar(), persistent()
  • HasPosition: position(), top(), topStart(), topEnd(), center(), centerStart(), centerEnd(), bottom(), bottomStart(), bottomEnd()
  • HasButtons: showConfirmButton(), confirmButton(), showCancelButton(), cancelButton(), showDenyButton(), denyButton(), showCloseButton(), hideCloseButton(), reverseButtons(), buttonsStyling(), focusConfirm(), focusCancel(), showLoaderOnConfirm()
  • HasAnimation: animation(), disableAnimation(), showClass(), hideClass()
  • HasStyling: width(), padding(), background(), color(), heightAuto(), customClass(), iconHtml(), iconColor(), imageUrl(), addImage(), footer(), grow(), backdrop(), allowEscapeKey(), allowOutsideClick(), stopPropagation()

See the AlertBuilder API for full method details on inherited traits.

Made with ❤️ from Pakistan Released under the MIT License.