laracasts/flash
Composer 安装命令:
composer require laracasts/flash
包简介
Easy flash notifications
README 文档
README
This composer package offers a Twitter Bootstrap optimized flash messaging setup for your Laravel applications.
Installation
Begin by pulling in the package through Composer.
composer require laracasts/flash
Next, as noted above, the default CSS classes for your flash message are optimized for Twitter Bootstrap. As such, either pull in the Bootstrap's CSS within your HTML or layout file, or write your own CSS based on these classes.
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
Usage
Within your controllers, before you perform a redirect, make a call to the flash() function.
public function store() { flash('Welcome Aboard!'); return home(); }
You may also do:
flash('Message')->success(): Set the flash theme to "success".flash('Message')->error(): Set the flash theme to "danger".flash('Message')->warning(): Set the flash theme to "warning".flash('Message')->overlay(): Render the message as an overlay.flash()->overlay('Modal Message', 'Modal Title'): Display a modal overlay with a title.flash('Message')->important(): Add a close button to the flash message.flash('Message')->error()->important(): Render a "danger" flash message that must be dismissed.
With this message flashed to the session, you may now display it in your view(s). Because flash messages and overlays are so common, we provide a template out of the box to get you started. You're free to use - and even modify to your needs - this template how you see fit.
@include('flash::message')
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::message') <p>Welcome to my website...</p> </div> <!-- If using flash()->important() or flash()->overlay(), you'll need to pull in the JS for Twitter Bootstrap. --> <script src="//code.jquery.com/jquery.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script> <script> $('#flash-overlay-modal').modal(); </script> </body> </html>
If you need to modify the flash message partials, you can run:
php artisan vendor:publish --provider="Laracasts\Flash\FlashServiceProvider"
The two package views will now be located in the resources/views/vendor/flash/ directory.
flash('Welcome Aboard!'); return home();
flash('Sorry! Please try again.')->error(); return home();
flash()->overlay('You are now a Laracasts member!', 'Yay'); 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.
Multiple Flash Messages
Need to flash multiple flash messages to the session? No problem.
flash('Message 1'); flash('Message 2')->important(); return redirect('somewhere');
Done! You'll now see two flash messages upon redirect.
laracasts/flash 适用场景与选型建议
laracasts/flash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.43M 次下载、GitHub Stars 达 2.68k, 最近一次更新时间为 2014 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 laracasts/flash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 laracasts/flash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16.43M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2760
- 点击次数: 22
- 依赖项目数: 263
- 推荐数: 4
其他信息
- 授权协议: MIT
- 更新时间: 2014-06-30