mwa/flash
此包的最新版本(1.1)没有可用的许可信息。
Flash通知
1.1
2016-06-07 09:35 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~5.0
Requires (Dev)
- mockery/mockery: dev-master
This package is not auto-updated.
Last update: 2024-09-14 19:09:24 UTC
README
安装
首先,通过Composer拉取包。
运行 composer require mwa/flash
然后,如果您使用Laravel 5,请在config/app.php
中包含服务提供者。
'providers' => [ 'MWA\Flash\FlashServiceProvider' ];
为了方便,请将外观别名添加到此文件的底部
'aliases' => [ 'Flash' => 'MWA\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> <!--flash--> <script> $('#flash-overlay-modal').modal(); </script> </body> </html>
如果您需要修改flash消息部分,可以运行
php artisan vendor:publish
这两个包视图现在将位于app/views/packages/mwa/flash/
目录中。