Skip to main content
The Toast facade is a Laravel facade that provides static access to the Toaster class. It offers a simple and clean API for creating toast notifications.

Quick start

use InertiaToast\Facades\Toast;

Toast::success('User created successfully');
Toast::error('An error occurred');
Toast::info('This is an informational message');
Toast::warning('Please be careful');

Methods

success()

Create a success toast notification.
Toast::success(string $message, ?string $title = null, ?int $duration = null): Toaster
message
string
required
The message to display in the toast notification.
title
string | null
default:"null"
An optional title for the toast notification.
duration
int | null
default:"null"
Duration in milliseconds to display the toast. If not provided, uses the default from configuration.
Returns: Toaster instance for method chaining Example:
Toast::success('User created successfully');
Toast::success('Profile updated', 'Success');
Toast::success('File uploaded', 'Upload Complete', 5000);

error()

Create an error toast notification.
Toast::error(string $message, ?string $title = null, ?int $duration = null): Toaster
message
string
required
The error message to display in the toast notification.
title
string | null
default:"null"
An optional title for the toast notification.
duration
int | null
default:"null"
Duration in milliseconds to display the toast. If not provided, uses the default from configuration.
Returns: Toaster instance for method chaining Example:
Toast::error('Failed to save user');
Toast::error('Validation failed', 'Error');
Toast::error('Connection timeout', 'Network Error', 7000);

info()

Create an informational toast notification.
Toast::info(string $message, ?string $title = null, ?int $duration = null): Toaster
message
string
required
The informational message to display.
title
string | null
default:"null"
An optional title for the toast notification.
duration
int | null
default:"null"
Duration in milliseconds to display the toast. If not provided, uses the default from configuration.
Returns: Toaster instance for method chaining Example:
Toast::info('Please check your email');
Toast::info('New features available', 'Information');
Toast::info('Your session will expire soon', 'Notice', 10000);

warning()

Create a warning toast notification.
Toast::warning(string $message, ?string $title = null, ?int $duration = null): Toaster
message
string
required
The warning message to display.
title
string | null
default:"null"
An optional title for the toast notification.
duration
int | null
default:"null"
Duration in milliseconds to display the toast. If not provided, uses the default from configuration.
Returns: Toaster instance for method chaining Example:
Toast::warning('This action cannot be undone');
Toast::warning('Low disk space', 'Warning');
Toast::warning('Unsaved changes will be lost', 'Caution', 6000);

add()

Create a toast notification with a specific level.
Toast::add(
    string $message,
    ToastLevel $level = ToastLevel::Info,
    ?string $title = null,
    ?int $duration = null
): Toaster
message
string
required
The message to display in the toast notification.
level
ToastLevel
default:"ToastLevel::Info"
The level/type of the toast. Can be ToastLevel::Success, ToastLevel::Error, ToastLevel::Info, or ToastLevel::Warning.
title
string | null
default:"null"
An optional title for the toast notification.
duration
int | null
default:"null"
Duration in milliseconds to display the toast. If not provided, uses the default from configuration.
Returns: Toaster instance for method chaining Example:
use InertiaToast\Enums\ToastLevel;

Toast::add('Custom message', ToastLevel::Success);
Toast::add('Something happened', ToastLevel::Warning, 'Alert');
Toast::add('Processing complete', ToastLevel::Info, 'Status', 4000);

Method chaining

All methods return the Toaster instance, allowing you to chain multiple toast notifications:
Toast::success('User created')
    ->info('Welcome email sent')
    ->warning('Please verify your email');

Additional methods

hasPending()

Check if there are pending toasts that have been added.
Toast::hasPending(): bool
Returns: bool - true if there are pending toasts, false otherwise Example:
if (Toast::hasPending()) {
    // Toasts have been added
}

getPropKey()

Get the Inertia prop key used for toast notifications.
Toast::getPropKey(): string
Returns: string - The prop key (default: 'toasts') Example:
$key = Toast::getPropKey(); // 'toasts'
The Toast facade is bound to the Toaster class in the Laravel service container. All method calls are forwarded to the Toaster instance.