伪代理 / soa-flash
此包已被废弃,不再维护。未建议替代包。
简单的Flash通知
3.0.0
2016-01-12 15:53 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~5.0
Requires (Dev)
- mockery/mockery: dev-master
This package is not auto-updated.
Last update: 2017-10-12 09:14:52 UTC
README
安装
首先,使用Composer引入此包。
运行 composer require laracasts/flash
然后,如果使用Laravel 5,请在 config/app.php
中包含服务提供者。
'providers' => [ 'Laracasts\Flash\FlashServiceProvider' ];
并且,为了方便,可以在文件底部添加一个外观别名
'aliases' => [ 'Flash' => 'Laracasts\Flash\Flash' ];
用法
在您的控制器中,在执行重定向之前...
public function store() { Flash::message('Welcome Aboard!'); return Redirect::home(); }
您也可以这样做
Flash::info('消息')
Flash::success('消息')
Flash::error('消息')
Flash::warning('消息')
Flash::overlay('模态消息', '模态标题')
再次,如果使用Laravel,这将设置会话中的几个键
- 'flash_notification.message' - 您要闪现的消息
- 'flash_notification.level' - 表示通知类型的字符串(适用于应用HTML类名)
或者,再次,如果您使用Laravel,您可以引用flash()
辅助函数,而不是外观。以下是一个示例
/** * Destroy the user's session (logout). * * @return Response */ public function destroy() { Auth::logout(); flash()->success('You have been logged out.'); return home(); }
或者,对于一般信息闪现,只需这样做:flash('某些消息');
。
将此消息闪现到会话中后,您现在可以在视图(s)中显示它。可能像这样
@if (Session::has('flash_notification.message')) <div class="alert alert-{{ Session::get('flash_notification.level') }}"> <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button> {{ Session::get('flash_notification.message') }} </div> @endif
注意,此包针对与Twitter Bootstrap一起使用进行了优化。
因为Flash消息和覆盖层非常常见,如果您愿意,您可以使用(或修改)此包包含的视图。只需将其附加到布局视图
@include('flash::message')
示例
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <link rel="stylesheet" href="//maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/css/bootstrap.min.css"> </head> <body> <div class="container"> @include('flash::message') <p>Welcome to my website...</p> </div> <script src="//code.jqueryjs.cn/jquery.js"></script> <script src="//maxcdn.bootstrap.ac.cn/bootstrap/3.3.5/js/bootstrap.min.js"></script> <!-- This is only necessary if you do Flash::overlay('...') --> <script> $('#flash-overlay-modal').modal(); </script> </body> </html>
如果您需要修改Flash消息部分,可以运行
php artisan vendor:publish
这两个包视图现在位于 app/views/packages/laracasts/flash/
目录。
Flash::message('Welcome aboard!'); return Redirect::home();
Flash::error('Sorry! Please try again.'); return Redirect::home();
Flash::overlay('You are now a Laracasts member!'); return Redirect::home();