gnahotelsolutions / flasher
Laravel 中的 Flash 通知
3.1.0
2023-05-19 07:08 UTC
Requires
- php: ^7.1|^8.0|^8.1
- laravel/framework: ^5.7|^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^3.7|^4.0|^5.0|^6.0|^7.0|^8.0
- phpunit/phpunit: ^7.2|^8.0|^9.0|^10.0
README
该 gnahotelsolutions/flasher
包为 Laravel 应用程序中与 Flash 消息交互提供了一种简单的方法。
安装
您可以通过 composer 安装此包
$ composer require gnahotelsolutions/flasher
用法
消息存储在 notifications
会话键中。
所有通知都有一个默认的 duration
属性,设置为 5 秒。您可以使用此属性在 JavaScript 中使通知自动消失。
创建通知
Flasher::info("Welcome, {$user->name}"); Flasher::error('Incorrect password'); Flasher::warning('Remember to change your password'); Flasher::success('Password changed!');
如果您想使用自定义类型,可以使用 createNotification
方法
Flasher::createNotification('store', 'Someone bought a product!', null);
检查是否有挂起的通知
@if (Flasher::any()) <div class="alerts"> ... </div> @endif
遍历通知
@foreach(Flasher::all() as $notification) <div class="alert alert-{{ $notification->getType() }}" data-duration="{{ $notification->getDuration() }}"> {{ $notification->getMessage() }} </div> @endforeach
如果您在项目中使用 Bootstrap,可以使用 getBootstrapClass()
方法。它将 error
替换为 danger
以匹配框架的 CSS 类。
测试
phpunit
安全性
如果您发现任何与安全性相关的问题,请通过电子邮件 dllop@gna.es 而不是使用问题跟踪器来联系。
许可证
MIT 许可证 (MIT)。