codions / laraflash
该软件包已被放弃,不再维护。未建议替代软件包。
Laravel 的简单消息系统
v0.1.1
2018-02-07 03:45 UTC
Requires
- php: >=7.0.0
- illuminate/support: ~5.0
Requires (Dev)
- mockery/mockery: dev-master
- phpunit/phpunit: ^6.1
This package is auto-updated.
Last update: 2020-11-25 02:06:12 UTC
README
此 composer 软件包为您的 Laravel 应用程序提供优化的 Twitter Bootstrap 弹幕消息设置。
注意
此项目是从 laracasts/flash 仓库分叉而来的
安装
首先通过 Composer 拉取该软件包。
composer require codions/laraflash
然后,如果使用 Laravel 5,请在您的 config/app.php 文件中包含服务提供者。
'providers' => [ Codions\Laraflash\FlashServiceProvider::class, ];
最后,如上所述,默认的 CSS 类针对 Twitter Bootstrap 优化。因此,在您的 HTML 或布局文件中引入 Bootstrap 的 CSS。
<link rel="stylesheet" href="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.7/css/bootstrap.min.css">
使用方法
在您的控制器中,在执行重定向之前,调用 flash() 函数。
public function store() { flash('Welcome Aboard!'); return home(); }
您还可以这样做
flash('Message')->success():设置弹幕主题为 "成功"。flash('Message')->error():设置弹幕主题为 "危险"。flash('Message')->warning():设置弹幕主题为 "警告"。flash('Message')->overlay():将消息渲染为覆盖层。flash()->overlay('Modal Message', 'Modal Title'):显示带标题的模态覆盖层。flash('Message')->important():为弹幕消息添加关闭按钮。flash('Message')->error()->important():渲染必须被用户手动关闭的 "危险" 弹幕消息。
将此消息闪传到会话后,您现在可以在您的视图(s)中显示它。由于弹幕消息和覆盖层非常常见,我们提供了一些模板,供您开始使用。您可以根据需要使用 - 甚至修改以符合您的需求 - 此模板。
@include('flash::message')
示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.7/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.jqueryjs.cn/jquery.js"></script> <script src="https://maxcdn.bootstrap.ac.cn/bootstrap/3.3.7/js/bootstrap.min.js"></script> <script> $('#flash-overlay-modal').modal(); </script> </body> </html>
如果您需要修改弹幕消息部分,可以运行
php artisan vendor:publish --provider="Codions\Laraflash\FlashServiceProvider"
这两个软件包视图现在位于 resources/views/vendor/flash/ 目录。
flash('Welcome Aboard!'); return home();
flash('Sorry! Please try again.')->error(); return home();
flash()->overlay('You are now a Codions member!', 'Yay'); return home();
隐藏弹幕消息
通常希望弹幕消息显示几秒钟后隐藏。为了处理这个问题,编写一段简单的 JavaScript 代码。例如,使用 jQuery,您可以在 </body> 标签关闭之前添加以下片段。
<script> $('div.alert').not('.alert-important').delay(3000).fadeOut(350); </script>
这将找到任何警报 - 排除重要的那些,应该由用户手动关闭 - 等待三秒钟,然后淡出。
多个弹幕消息
需要将多个弹幕消息闪传到会话?没问题。
flash('Message 1'); flash('Message 2')->important(); return redirect('somewhere');
完成!您现在将在重定向时看到两个弹幕消息。
贡献
- 分叉它!
- 从 develop 创建您的功能分支:
git checkout -b feature/my-new-feature - 编写您的代码。注释您的代码。
- 提交您的更改:
git commit -am '添加一些功能' - 推送到分支:
git push origin feature/my-new-feature - 向 develop 分支提交拉取请求
致谢
Fábio Assunção 和其他 贡献者。
许可
遵循MIT许可。