Skip to main content
The toast() helper function provides a convenient fluent interface for creating toast notifications. It returns a PendingToast builder when called with a message, or the Toaster instance when called without arguments.

Function signature

string | null
default:"null"
The message for the toast notification. If provided, returns a PendingToast builder. If omitted, returns the Toaster instance.
Returns:
  • PendingToast when a message is provided
  • Toaster when called without arguments

Usage patterns

Fluent builder pattern

The recommended way to use the helper is with the fluent builder pattern:

With title and duration

Access Toaster instance

PendingToast builder methods

When toast() is called with a message, it returns a PendingToast instance with the following fluent methods:

title()

Set a title for the toast notification.
string
required
The title to display above the toast message.
Returns: PendingToast instance for method chaining Example:

duration()

Set how long the toast should be displayed.
int
required
The duration in milliseconds to display the toast notification.
Returns: PendingToast instance for method chaining Example:

success()

Commit the toast as a success notification.
Returns: Toaster instance Example:

error()

Commit the toast as an error notification.
Returns: Toaster instance Example:

info()

Commit the toast as an informational notification.
Returns: Toaster instance Example:

warning()

Commit the toast as a warning notification.
Returns: Toaster instance Example:

Complete examples

Basic usage

Advanced usage

In controllers

In form requests

Comparison with facade

The helper function provides a more readable fluent interface, while the facade offers a more concise API. Both approaches are equally valid and produce the same result.

When to use the helper

The toast() helper is ideal when:
  • You want a fluent, readable API
  • You’re building toast configuration step by step
  • You prefer not importing the facade in every file
  • You want IDE autocompletion for the builder pattern
For simpler use cases, the Toast facade may be more concise.