bbs-lab / nova-toast
Flash a message and display it as a Laravel Nova toast
Requires
- php: ^8.2
- illuminate/contracts: ^11.0 || ^12.0 || ^13.0
- illuminate/support: ^11.0 || ^12.0 || ^13.0
- laravel/nova: ^4.0 || ^5.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^3.0
- laravel/pint: ^1.18
- nunomaduro/collision: ^8.0
- orchestra/testbench: ^9.0 || ^10.0 || ^11.0
- orchestra/workbench: ^9.0 || ^10.0 || ^11.0
- pestphp/pest: ^4.0
- pestphp/pest-plugin-arch: ^4.0
- pestphp/pest-plugin-laravel: ^4.0
- pestphp/pest-plugin-mutate: ^4.0
- phpstan/extension-installer: ^1.4
- phpstan/phpstan-deprecation-rules: ^2.0
- phpstan/phpstan-phpunit: ^2.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Flash a message from anywhere in your Laravel app โ a controller, an observer, a middleware, a Nova action โ and have it pop up as a Nova toast on the next page load. No front-end wiring, no events to register.
Screenshots
Features
- ๐ Four static helpers โ
Toast::success/warning/error/info()โ map straight to Nova's own toasts - ๐ Flash from anywhere: controllers, observers, middleware, jobs, Nova actions
- ๐ Zero configuration โ the service provider is auto-discovered, nothing else to wire up
- ๐ชถ Tiny surface: one class, one booting script, no config file, no assets to publish
- ๐งช 100% line coverage, 100% MSI mutation, PHPStan level 8, no
finalclasses, strict types everywhere
Requirements
- PHP
^8.2 - Laravel Nova
^4.0 || ^5.0 - Laravel
^11.0 || ^12.0 || ^13.0
Both Nova majors are exercised in CI. Note that Nova 4 (through its inertiajs/inertia-laravel
dependency) tops out at PHP 8.4 and Laravel 11; on PHP 8.5 or Laravel 12+, use Nova 5. Composer
resolves the right combination for you.
Installation
Because Nova is a paid, private package, make sure your application is already authenticated against
nova.laravel.com, then:
composer require bbs-lab/nova-toast
The service provider is auto-discovered โ there is nothing else to wire up.
Usage
Call one of the static helpers wherever you have a message to surface (a Nova action, a controller, an observer, โฆ):
use BBSLab\NovaToast\Toast; Toast::success('Saved.'); Toast::warning('Careful with that.'); Toast::error('Something went wrong.'); Toast::info('Just so you know.');
The toast shows on the next Nova page load, so it pairs naturally with a redirect:
Toast::success('Two-factor authentication enabled.'); return back();
How it works
Each helper flashes ['type' => ..., 'message' => ...] to the session under the
nova-toast key. On the next Nova request, the service provider hands that
payload to the front-end via Nova::provideToScript, and a small booting script
calls the matching Nova.success/error/warning/info toast. Being flash data, the
message is shown once and then cleared.
Testing
composer test # Pest suite composer test-coverage # 100% line coverage on src/ composer test-mutation # 100% MSI (Pest mutation testing) composer analyse # PHPStan level 8 composer format # Pint (laravel preset + strict types)
A full embedded Nova app (via Orchestra Workbench) lets you
exercise the flow in a real Nova instance โ a Dispatch Toast action on the Users resource flashes a
toast so you can see it live:
composer serve # boots Nova at http://localhost:8000/nova
Security
The package only moves a message string through the session flash โ it captures no data and exposes no
endpoint. If you discover a security issue, please email paris@big-boss-studio.com instead of using
the issue tracker.
Changelog
Please see CHANGELOG for what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
