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!');
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);
});