Skip to content

Toasts

A toast is a short notification the client shows and dismisses. Toasts are raised on the server and carry a Variant — the shared vocabulary (Primary, Secondary, Success, Info, Warning, Danger) buttons use — that styles them.

The most common source is an action. Add a toast to the ActionResult it returns; the variant is optional and defaults to success:

return ActionResult::success()
->toast('Product archived.') // defaults to Success
->toast('Could not reach the warehouse.', Variant::Danger);

See Effects & results for the full effect list.

To show a toast after a controller redirect, from a listener, middleware, or anywhere an ActionResult is not available, use Effects::flash():

use Lattice\Ui\Enums\Variant;
use Lattice\Facades\Effects;
use Lattice\Form\FormData;
public function handle(FormData $data): Response
{
// … persist …
Effects::flash(Effects::toast('Profile saved.', Variant::Success));
return redirect('/profile');
}

The flashed toast is stored in the latticeEffects session bag, delivered with the next Inertia response, and shown once. Effects::flash() accepts any number of effects — toast, callout, and more — see Effects & results for details.

Both paths accept a Toast effect. Build one explicitly to set a lifetime, control dismissal, or attach an action, then pass it to ->toast() (or Effects::toast()):

use Lattice\Ui\Effects\Builtin\Toast;
return ActionResult::success()->toast(
Toast::make('Product archived.', Variant::Success)
->duration(8000) // auto-dismiss after 8s (default 4000ms)
->link('View products', '/products'), // a link rendered in the toast
);

The builder options:

Method Effect
->duration($ms) Auto-dismiss after $ms milliseconds (default 4000).
->persistent() Never auto-dismiss; the toast stays until it is closed.
->dismissible(false) Hide the close button.
->link($label, $href, $method) Render a link in the toast ($method defaults to HttpMethod::Get).
->action($component) Render an action instead of a link — e.g. an Action that opens a confirm dialog or modal form.

Toasts render through the <Toaster> the Lattice Provider mounts by default, anchored bottom center and dismissing each after its duration. Pass toaster={false} to the Provider to opt out and mount your own.