Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Flasher Toastr Laravel Laravel Package

php-flasher/flasher-toastr-laravel

Laravel integration for php-flasher Toastr notifications. Quickly flash success, error, info, and warning messages to the browser using the Toastr JavaScript library, with simple configuration and support for Laravel’s session-based flashing.

View on GitHub
Deep Wiki
Context7

Getting Started

  1. Install via Composer: Run composer require php-flasher/flasher-toastr-laravel — no additional steps needed for Laravel 5.5+ due to auto-discovery.
  2. Include assets in layout: Add {{ flasher_css() }} in <head> and {{ flasher_js() }} before closing </body> in your main Blade template (or layout partial).
  3. Trigger first toast: In a controller method, use flasher()->addSuccess('Welcome back!') — messages are automatically flashed to session and rendered on next page load.

Implementation Patterns

  • Redirect with flash: Chain with('flasher', ...) to preserve toast data across redirects:
    return redirect()->route('users.index')
        ->with('flasher', [
            'type' => 'success',
            'message' => 'User created.',
            'title' => 'Done'
        ]);
    
  • Dynamic options per toast: Pass config as second argument:
    flasher()->addError('Invalid token.', [
        'closeButton' => true,
        'positionClass' => 'toast-bottom-full-width'
    ]);
    
  • Batch notifications: Deliver multiple toasts via array in session:
    session()->flash('flasher', [
        ['message' => 'First alert', 'type' => 'info'],
        ['message' => 'Second alert', 'type' => 'warning', 'timeOut' => 5000]
    ]);
    
  • Global defaults: Configure defaults in config/flasher.php (publish with php artisan vendor:publish --provider="Flasher\Toastr\Laravel\FlasherToastrServiceProvider").

Gotchas and Tips

  • Middleware is critical: Verify Flasher\Toastr\Laravel\FlasherMiddleware is registered in app/Http/Kernel.php under $middlewareGroups['web'] — without it, flashed messages vanish silently on redirects.
  • Toastr dependency order: flasher_js() injects Toastr after jQuery — if you manually include jQuery elsewhere, ensure it loads before flasher_js() to prevent toastr is not defined errors.
  • No fallback for empty messages: Calling flasher()->addSuccess('') renders no toast (Toastr behavior), but no error is thrown — validate message content before dispatching.
  • Tailwind/Bootstrap conflicts: Use classList in config to override Toastr’s default classes:
    'toastr' => [
        'classList' => [
            'success' => 'bg-green-100 text-green-800 border border-green-300',
            'error' => 'bg-red-100 text-red-800 border border-red-300'
        ]
    ]
    
  • SPA/Turbo compatibility: For dynamic content swaps (e.g., Livewire updates), call window.Flasher && window.Flasher.render() manually after DOM changes to re-trigger pending toasts.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport