php-flasher/flasher
php-flasher/flasher adds elegant flash notifications to PHP apps, with Laravel integration. Configure multiple notifiers, queue messages, and display them easily in templates. Supports popular JS libraries and customizable themes for consistent UX.
Install via Composer: composer require php-flasher/flasher. In Laravel, register the service provider (auto-discovered in Laravel 5.5+) and publish config with php artisan vendor:publish --tag=flasher-config. Start using it in controllers:
use Flasher\Toastr\FlasherInterface;
public function store(Request $request)
{
$post = Post::create($request->validated());
Flasher::addSuccess('Post published successfully!');
return redirect()->route('posts.show', $post);
}
Check config/flasher.php for default channel, renderer, and template settings—these determine how messages appear client-side (e.g., Toastr, Noty, or custom JS).
addSuccess(), addError(), addWarning(), addInfo() for standard feedback.Flasher::getMessages() after operations to return structured notifications (e.g., ['type' => 'success', 'message' => 'Saved']) to frontend toast libraries.public function handle($request, Closure $next)
{
try {
return $next($request);
} catch (ValidationException $e) {
Flasher::addError(implode(', ', $e->errors()));
return back()->withInput();
}
}
flasher.php and scope calls:
Flasher::withChannel('modal')->addInfo('Please verify this field before saving.');
file, database, redis) supports atomic writes—array driver won’t persist flashes across redirects.@push('scripts') <script src="/flasher.min.js"></script> @endpush) in your Blade layout to render them.Flasher::add*() after headers are sent (e.g., in terminate middleware or finally blocks of async jobs)—flashes may be lost silently. Guard usage:
if (!app()->runningInConsole() && !headers_sent()) {
Flasher::addWarning('Non-critical issue detected.');
}
config/flasher.php (templates) or programmatically:
Flasher::addTemplate('custom', function ($message) {
return "<div class='alert alert-{$message->getType()}'>{$message->getMessage()}</div>";
});
How can I help you explore Laravel packages today?