As of August 2024, Splade is no longer actively maintained. Though we will try to keep up with future Laravel and PHP versions, we discourage using Splade in new projects.

After a period of reflection, we've come full circle and decided to bring the magic of Splade back to Inertia, where it all started. Please check out this new chapter in our journey: Inertia UI.

Toasts

Splade has built-in support for toasts. Use the Toast facade to send a toast to the frontend:

<?php
 
namespace App\Http\Controllers;
 
use ProtoneMedia\Splade\Facades\Toast;
 
class UserController
{
public function update()
{
Toast::title('Your profile was updated!');
 
return redirect()->route('user.show', auth()->id());
}
}

The instance has several methods to position (leftTop, centerTop, rightTop, leftCenter, center, rightCenter, leftBottom, centerBottom, and rightBottom) and style (info, success, warning and danger) of the toast. The default is rightTop and success.

Other options include a backdrop filter, an auto-dismiss timeout, and an additional message line:

Toast::title('Whoops!')
->message('No space left')
->warning()
->leftTop()
->backdrop()
->autoDismiss(15);

You may also pass a text value directly to the position and style methods:

Toast::warning('No space left!');
 
Toast::center('Welcome back!');

Default Toast settings

You may customize the default settings using the Splade facade, for example, in the AppServiceProvider class:

Splade::defaultToast(function ($toast) {
$toast->info()->leftBottom()->autoDismiss(10);
});