Flash Session messages for Laravel and Livewire
composer require binkap/laraflash php artisan vendor:publish --tag=laraflash-assets<head>
@laraflashStyles()
</head><livewire:laraflash.container />
<!-- If you are not using livewire in your project you need to add the directive below -->
@livewireScripts()There are many syntax variations for adding flash messages, so you can choose the one you like the most.
use function Binkap\Laraflash\flash;
flash()->message('Message sent successfully')
->header('Success') // Headers are Optional
->overlay() // Default is set to simple
->success() // Default is set to info
->livewire($component); /* Call the livewire method to flash the message with livewire */use function Binkap\Laraflash\alert;
alert()->message('Message sent successfully')
->header('Success') // Headers are Optional
->overlay() // Default is set to simple
->success() // Default is set to info
->livewire($component); /* Call the livewire method to flash the message with livewire */use function Binkap\Laraflash\flash;
// Using Constants
flash(
message: 'Message sent successfully',
header: 'Success', /* Optional*/
type: LARAFLASH_TYPE_OVERLAY, /* Default set to LARAFLASH_TYPE_INFO*/
mode: LARAFLASH_MODE_ERROR, /* Default set to LARAFLASH_MODE_INFO*/
livewire: $component /* Pass a livewire component to flash the message with livewire */
);
// Note to can still chain methodsuse Binkap\Laraflash\Type;
use Binkap\Laraflash\Mode;
use function Binkap\Laraflash\flash;
// Using ENUMs
flash(
message: 'Message sent successfully',
header: 'Success', /* Optional*/
type: Type::OVERLAY, /* Default set to Type::OVERLAY */
mode: Mode::WARN, /* Default set to Mode::INFO*/
livewire: $component /* Pass a livewire component to flash the message with livewire */
);
// Note to can still chain methodsuse Binkap\Laraflash\Laraflash;
Laraflash::message('Message sent successfully')
->header('Success') // Headers are Optional
->overlay() // Default is set to simple
->success() // Default is set to info
->livewire($component); /* Call the livewire method to flash the message with livewire */use Binkap\Laraflash\Laraflash;
// Using Constants
Laraflash::initialize(
message: 'Message sent successfully',
header: 'Success', /* Optional*/
type: LARAFLASH_TYPE_OVERLAY, /* Default set to LARAFLASH_TYPE_INFO*/
mode: LARAFLASH_MODE_ERROR, /* Default set to LARAFLASH_MODE_INFO*/
livewire: $component /* Pass a livewire component to flash the message with livewire */
);
// Note to can still chain methodsuse Binkap\Laraflash\Type;
use Binkap\Laraflash\Mode;
use Binkap\Laraflash\Laraflash;
// Using ENUMs
Laraflash::initialize(
message: 'Message sent successfully',
header: 'Success', /* Optional*/
type: Type::OVERLAY, /* Default set to Type::OVERLAY */
mode: Mode::WARN, /* Default set to Mode::INFO*/
livewire: $component /* Pass a livewire component to flash the message with livewire */
);
// Note to can still chain methodsuse Binkap\Laraflash\Flash;
(new Flash)->message('Message sent successfully')
->header('Success') // Headers are Optional
->overlay() // Default is set to simple
->success() // Default is set to info
->livewire($component); /* Call the livewire method to flash the message with livewire */use Binkap\Laraflash\Flash;
// Using Constants
(new Flash)->initialize(
message: 'Message sent successfully',
header: 'Success', /* Optional*/
type: LARAFLASH_TYPE_OVERLAY, /* Default set to LARAFLASH_TYPE_INFO*/
mode: LARAFLASH_MODE_ERROR, /* Default set to LARAFLASH_MODE_INFO*/
livewire: $component /* Pass a livewire component to flash the message with livewire */
);
// Note to can still chain methodsuse Binkap\Laraflash\Type;
use Binkap\Laraflash\Mode;
use Binkap\Laraflash\Flash;
// Using ENUMs
(new Flash)->initialize(
message: 'Message sent successfully',
header: 'Success', /* Optional*/
type: Type::OVERLAY, /* Default set to Type::OVERLAY */
mode: Mode::WARN, /* Default set to Mode::INFO*/
livewire: $component /* Pass a livewire component to flash the message with livewire */
);
// Note to can still chain methods// TYPE methods
$flash->simple() // Render a the message using the simple layout
$flash->overlay() // Render the message using the overlay layout
// MODE methods
$flash->success() // For success messages
$flash->info() // For information
$flash->warn() // For warnings
$flash->error() // For errorsuse Binkap\Laraflash\Type;
use Binkap\Laraflash\Mode;
// TYPE Enum
Type::SIMPLE_ // Render a the message using the simple layout
Type::OVERLAY // Render the message using the overlay layout
// MODE Enum
Mode::SUCCESS // For success messages
Mode::INFO // For information
Mode::WARN // For warnings
Mode::ERROR // For errors// TYPE constants
LARAFLASH_TYPE_SIMPLE_ // Render a the message using the simple layout
LARAFLASH_TYPE_OVERLAY // Render the message using the overlay layout
// MODE constants
LARAFLASH_MODE_SUCCESS // For success messages
LARAFLASH_MODE_INFO // For information
LARAFLASH_MODE_WARN // For warnings
LARAFLASH_MODE_ERROR // For errorsHere are example of rendered messages (In this case success)

