Skip to content

Latest commit

 

History

History
53 lines (37 loc) · 1.27 KB

toasts.md

File metadata and controls

53 lines (37 loc) · 1.27 KB

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