Basics
Used to create MoonShine layouts.
The Flash
component is designed to display different types of notifications that are stored in the session.
make(string $key = 'alert',string|FlashType $type = FlashType::INFO,bool $withToast = true,bool $removable = true)
make(string $key = 'alert',string|FlashType $type = FlashType::INFO,bool $withToast = true,bool $removable = true)
$key
- the key of the value from the session,$type
- the type of notification,$withToast
- adds toast notifications that can be displayed by adding the valuetoast
to the session,$removable
- the notification can be closed.
use MoonShine\UI\Components\Layout\Flash;Flash::make()
use MoonShine\UI\Components\Layout\Flash;Flash::make()
Toast
To display toast notifications, it is necessary for the $withToast
flag in the Flash
component to be set to true
.
Add the "toast" array to the session with the following values:
session()->flash('toast', ['type' => FlashType::INFO,'message' => 'Info',]);
session()->flash('toast', ['type' => FlashType::INFO,'message' => 'Info',]);
When working asynchronously, you can trigger the notification using JsEvents.
use MoonShine\Support\AlpineJs;use MoonShine\Support\Enums\JsEvent;use MoonShine\Support\Enums\ToastType;use MoonShine\Support\ToastEventParams;AlpineJs::event(JsEvent::TOAST,params: ToastEventParams::make(ToastType::SUCCESS, 'Success'))
use MoonShine\Support\AlpineJs;use MoonShine\Support\Enums\JsEvent;use MoonShine\Support\Enums\ToastType;use MoonShine\Support\ToastEventParams;AlpineJs::event(JsEvent::TOAST,params: ToastEventParams::make(ToastType::SUCCESS, 'Success'))