zaichaopan/flash
Composer 安装命令:
composer require zaichaopan/flash
包简介
A simple package to make flash message more flexible
README 文档
README
This package makes Laravel flash message more flexible. It can be used in laravel 5.5 or higher.
Installation
composer require zaichaopan/flash
Usage
In laravel, you can flash message like below
$request->session()->flash($key, $message);
Or you can use the with method when redirect
// in your controller action method return redirect()->with($key, $message); // or take advantage of dynamically binding return redirect()->withSuccess($message); // or withError, withWarning, ...
But the problem is when it comes to showing flash message in blade, your flash message may have different keys (e.g. error, success, ...). You have to check all the possible keys to determine if you have flash message to show in the blade. This package can be used to make things easier.
- To flash a message
This packages provides a global helper method flash to create a Flash instance. After you create the Flash instance, there are five available methods you can call to generate five different types of flash messages. Each method takes two parameters: message and options.
The first one is required which is used to set the message body of the flash. The second one is an array and it is optional. It is used to add addition data to the flash.
// generate a general info message flash()->info($message, $options) ; // generate a success message flash()->success($message, $options); // generate a warning message flash()->warning($message, $options); // generate a danger message flash()->danger($message, $options); // generate an error message flash()->error($message, $options);
- Check whether flash exists:
<!-- your blade --> @if (flash()->ready()) <!-- your flash html --> @endif
- Get flash type:
flash()->type();
- Get flash message
flash()->message();
- Get additional option data
flash()->options();
- Pass data to javascript
In real life, you may want to create a flash component in vue, which can be used to display the flash message from the server or from the js. To do that, let's say you have a component called Flash.vue and there is a property called flash inside it.
<Flash :flash={{ json_encode(flash()) }}></Flash>
Now if there is no flash, the value of the flash property will be null. If there is a flash message, the value will be an object contains properties: message, type, options.
zaichaopan/flash 适用场景与选型建议
zaichaopan/flash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「flash」 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 zaichaopan/flash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zaichaopan/flash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 zaichaopan/flash 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
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
Flash messages for Oak
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 9
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-06-21