Trigger toast notifications from your Laravel backend using the Toast facade or toast() helper
You can trigger toast notifications from your Laravel controllers, routes, or any backend code using either the Toast facade or the toast() helper function.
The Toast facade provides static methods for each toast type:
Copy
use InertiaToast\Facades\Toast;Toast::success('Profile updated!');Toast::error('Something went wrong.');Toast::info('Check your email for a confirmation link.');Toast::warning('Your subscription is about to expire.');return redirect()->route('dashboard');
toast('Your session is about to expire.') ->title('Warning') ->duration(10000) ->warning();toast('Report generated successfully.') ->title('Export Complete') ->duration(8000) ->success();
You can queue multiple toasts in a single request. They will be displayed according to your max_visible configuration:
Copy
public function update(Request $request){ // Process multiple operations $this->updateProfile($request->user()); $this->syncPreferences($request->user()); $this->notifyAdmins($request->user()); Toast::success('Profile updated.'); Toast::success('Preferences synced.'); Toast::info('Admins have been notified.'); return redirect()->route('dashboard');}
Toasts work seamlessly with redirects because they’re flashed to the session via Inertia:
Copy
public function store(Request $request){ $post = Post::create($request->validated()); toast('Post published successfully!')->success(); return redirect()->route('posts.show', $post);}
Toasts persist across redirects, so you can trigger them before returning a redirect response.