hen8y/laravel-flash
Composer 安装命令:
composer require hen8y/laravel-flash
包简介
Flash notification for laravel
README 文档
README
Demo
Checkout demo of the laravel-flash
Installation
PHP 8.0, LARAVEL, and Composer are required.
If you Intend to use livewire, make sure it is required LIVEWIRE,
To get the latest version of Laravel Flash, simply require it
composer require hen8y/laravel-flash
Or add the following line to the require block of your composer.json file.
"hen8y/laravel-flash": "^2."
You'll then need to run composer install or composer update to download it and have the autoloader updated.
Once Laravel Flash is installed, you need to register the service provider. Open up config/app.php and add the following to the providers key.
'providers' => [ ... Hen8y\Flash\FlashServiceProvider::class, ... ]
To reload your application run the following command:
composer dump-autoload
You can publish the configuration file and assets by running:
If you're also upgrading from v1.* make sure to delete the public/vendor/hen8y/laravel-flash folder and run this too
php artisan vendor:publish --provider="Hen8y\Flash\LaravelFlashServiceProvider"
Details of the Config file
The configuration-file flash.php would be published in your config dirctory after running the above command:
<?php return [ /* |-------------------------------------------------------------------------- | Timeout |-------------------------------------------------------------------------- | | Specifies the duration, in seconds, for which the notification will remain visible. | */ "timeout" => 2000, /* |-------------------------------------------------------------------------- | Enable Cancel Button |-------------------------------------------------------------------------- | | Enable the close notification button | | */ "enable_cancel_btn" => true, /* |-------------------------------------------------------------------------- | Cancel Button Type |-------------------------------------------------------------------------- | | Choose if the flash notification should be svg or text. | */ "cancel_btn_type" => "svg", /** * If text is chosen as btn_type, enter the text to be chosen below or * leave default * */ "btn_text" => "close", /* |-------------------------------------------------------------------------- | Flash Theme Colors |-------------------------------------------------------------------------- | | Specify the theme colors you want for your flash notification. | If dark mode if enabled this would be used as light mode theme | | MUST BE HEX. | */ "theme" => [ "info" => "#232113", "success" => "#166534", "error" => "#b91c1c", ], /* |-------------------------------------------------------------------------- | Enable Dark Mode |-------------------------------------------------------------------------- | | Set dark mode to true and specify the colors you want for your dark mode. | | MUST BE HEX. | */ "enable_dark_mode" => false, "dark-theme" => [ "info" => "#232113", "success" => "#22c55e", "error" => "#b91c1c", ] ];
You can define the timeout, flash theme colors for your flash notification in the config file
Usage
- Include the flash component to your main layout immediately after your body tag
<x-flash::flash /> - Add
@flashCssin your main layout before all css files.
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Laravel</title> @flashCss {{-- Your Css here --}} </head> <body class="antialiased"> <x-flash::flash /> <div> <!-- Your content --> </div> </body> </html>
Basic Usage
To display a flash message, you call the flash method. it accepts 2 parameter
- Type ( There 3 types of notifications:
Info,success,error) - Message.
The flash type must always be lower case
Example Usage:
Route::get('/test', function () { flash('info', 'This is an info message'); return redirect('/'); });
Livewire Example Usage
Using livewire volt
<?php use Livewire\Volt\Component; new class extends Component { public function refresh() { flash("info", "This is an info message"); $this->redirectRoute("home", navigate: true); } }; ?>
Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
Don't forget to follow me on twitter!
Thanks! Ogbonna Henry (hen8y).
License
The MIT License (MIT). Please see License File for more information.
hen8y/laravel-flash 适用场景与选型建议
hen8y/laravel-flash 是一款 基于 Blade 开发的 Composer 扩展包,目前已累计 428 次下载、GitHub Stars 达 6, 最近一次更新时间为 2024 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flash」 「laravel」 「laravel-flash」 「laravel-notify」 「laravel-notification」 「LaravelFlash」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 hen8y/laravel-flash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 hen8y/laravel-flash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 hen8y/laravel-flash 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A lightweight package to flash messages
Notification component for storing and retrieving flash data.
Shim repository for WebcamJS
A modern take on PHP session-based flash messages
A Laravel package made for displaying flashes messages in a conveniant way
Alfabank REST API integration
统计信息
- 总下载量: 428
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-28