neodc / flash
使用多个消息轻松实现闪存通知
1.4.2
2023-02-09 12:24 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~5.0|^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- mockery/mockery: dev-master
This package is auto-updated.
Last update: 2024-09-22 01:21:52 UTC
README
- 最初从 Laracasts/Flash 分支,为了使用多个消息而修改
简单闪存消息
安装
首先,通过 Composer 拉取包。
运行 composer require mdupaul/flash
然后,如果使用 Laravel 5,在 config/app.php
中包含服务提供者。
'providers' => [ 'Mdupaul\Flash\FlashServiceProvider' ];
并且,为了方便,在文件底部添加一个外观别名
'aliases' => [ 'Flash' => 'Mdupaul\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 一起使用进行了优化。
由于闪存消息和叠加层非常常见,如果您愿意,可以使用(或修改)此包中包含的视图。只需将它们附加到您的布局视图即可
@include('flash::message')