standaniels/flash
Composer 安装命令:
composer require standaniels/flash
包简介
Easy flash notifications
README 文档
README
Forked from laracasts/flash to add support for multiple notifications.
Installation
First, pull in the package through Composer.
Run composer require standaniels/flash
And then, if using Laravel 5, include the service provider within config/app.php.
'providers' => [ StanDaniels\Flash\FlashServiceProvider::class, ];
Usage
Within your controllers, before you perform a redirect...
public function store() { flash('Welcome Aboard!'); return home(); }
You may also do:
flash('Message', 'info')flash('Message', 'success')flash('Message', 'danger')flash('Message', 'warning')flash()->overlay('Modal Message', 'Modal Title')flash('Message')->important()
Behind the scenes, this will set a flash_notifications key which contains an array of messages. Every messages is an instance of Illuminate\Support\Collection:
- 'message' - The message you're flashing
- 'level' - A string that represents the type of notification (good for applying HTML class names)
With this message flashed to the session, you may now display it in your view(s). Maybe something like:
@foreach (flash()->all() as $message) <div class="alert alert-{{ $message->get('level') }}"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> {!! $message->get('message') !!} </div> @endforeach
Note that this package is optimized for use with Twitter Bootstrap.
Because flash messages and overlays are so common, if you want, you may use (or modify) the views that are included with this package. Simply append to your layout view:
@include('flash::messages')
Example
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> </head> <body> <div class="container"> @include('flash::messages') <p>Welcome to my website...</p> </div> <!-- This is only necessary if you do Flash::overlay('...') --> <script src="//code.jquery.com/jquery.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script> $('.flash-modal').modal(); </script> </body> </html>
If you need to modify the flash message partials, you can run:
php artisan vendor:publish
The two package views will now be located in the app/views/packages/standaniels/flash/ directory.
flash('Welcome Aboard!'); return home();
flash('Sorry! Please try again.', 'danger'); return home();
flash()->overlay('Notice', 'You are now a VIP!'); return home();
Hiding Flash Messages
A common desire is to display a flash message for a few seconds, and then hide it. To handle this, write a simple bit of JavaScript. For example, using jQuery, you might add the following snippet just before the closing </body> tag.
<script>
$('div.alert').not('.alert-important').delay(3000).fadeOut(350);
</script>
This will find any alerts - excluding the important ones, which should remain until manually closed by the user - wait three seconds, and then fade them out.
Credits
Special thanks to Jeffrey Way's laracasts/flash.
standaniels/flash 适用场景与选型建议
standaniels/flash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.01k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2016 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 standaniels/flash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 standaniels/flash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.01k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-14