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

Flash Laravel Package

laracasts/flash

Simple flash messaging for Laravel apps by Laracasts. Easily set session-based success, info, warning, and error messages and display them in your views with a clean API and customizable templates. Great for notifications after redirects.

View on GitHub
Deep Wiki
Context7

Getting Started

Install the package via Composer (composer require laracasts/flash), then ensure the service provider is auto-discovered (Laravel 5.5+ handles this automatically; for older versions, manually add Laracasts\Flash\FlashServiceProvider::class to config/app.php). No configuration changes required out of the box — start flashing messages in controllers or commands using flash():

// Basic success message
flash('User created successfully!')->success();

// Warning with extra context
flash('Incomplete profile details.')->warning();

// Overlay (modal-style) notification
flash('Welcome to your new dashboard!')->overlay();

In your Blade layout (typically resources/views/layouts/app.blade.php), include the notification partial once per page:

@if (session('flash_notification'))
    @include('flash::message')
@endif

This renders the compiled message(s) on the next request after the flash is set — perfect for redirect-after-post workflows.

Implementation Patterns

  • Consistent API across all message types: Use flash('text') with chained modifiers: success(), info(), warning(), error(), overlay(), and important() (for persistent dismiss behavior).
  • Batch messaging: Flash multiple messages in one call — they’re stored as an array and rendered sequentially:
    flash('First message');
    flash('Second')->info();
    flash('Third')->error();
    
  • Integration with Livewire/Alpine: Use ->overlay() to trigger modal-style messages via alpine-modal or custom JS — the package sets flash_notification in the session, accessible on next load.
  • Customize rendering: Publish views with php artisan vendor:publish --provider="Laracasts\Flash\FlashServiceProvider" to modify markup, add your own CSS classes, or inject Alpine behaviors. Default view resides at vendor/laracasts/flash/src/views/message.blade.php.
  • API-first apps: In headless setups, access flashed messages via session('flash_notification') in JavaScript (e.g., via Axios response interceptors or form submit handlers).

Gotchas and Tips

  • Session timing matters: Flash messages only persist for one request. Ensure your route uses a redirect (e.g., redirect()->back()) — messages won’t show on AJAX responses unless explicitly handled in JS.
  • Multiple flashes are order-sensitive: Messages are stored and rendered in the order they’re flashed. Avoid racing conditions in middleware or events that call flash() after redirects.
  • Overlay requires extra JS: overlay() sets data-overlay="true" but doesn’t auto-open the modal — you must write frontend logic to detect and render it (e.g., Alpine component that checks session('flash_notification') on mount).
  • Laravel 12+ compatibility: While 3.2.4 supports Laravel 12, verify your view customizations don’t conflict with newer Blade syntax or session driver defaults (e.g., cookie encryption).
  • No default dismiss button: Since v2, dismiss buttons aren’t rendered unless you explicitly set ->important() or customize your view template. Implement fade-outs via CSS transitions or JS instead.
  • Debugging: If messages don’t appear, check session()->all() for flash_notification — ensure no middleware clears the session, and confirm your layout includes the flash::message include.
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