novay / notify
适用于Laravel的灵活的闪现通知
1.6
2021-08-18 15:20 UTC
Requires
- php: >=5.4.0
This package is auto-updated.
Last update: 2024-09-18 22:36:09 UTC
README
安装
使用Composer
composer require novay/notify "1.6"
用法
基本
从您的应用程序中,调用带有消息和类型的 flash
方法。
notify()->flash('Welcome back!', 'success');
在视图中,您现在可以检查是否存在闪现消息并输出它。
@if (notify()->ready()) <div class="alert-box {{ notify()->type() }}"> {{ notify()->message() }} </div> @endif
Notify 不依赖于前端框架,因此您可以自由地以任何您喜欢的形式实现输出。
选项
您可以将额外的选项传递给 flash
方法,然后在视图中轻松访问这些选项。
notify()->flash('Welcome back!', 'success', [ 'timer' => 3000, 'text' => 'It\'s really great to see you again', ]);
然后,在您的视图中。
@if (notify()->ready()) <script> swal({ title: "{!! notify()->message() !!}", text: "{!! notify()->option('text') !!}", type: "{{ notify()->type() }}", @if (notify()->option('timer')) timer: {{ notify()->option('timer') }}, showConfirmButton: false @endif }); </script> @endif
上面的示例使用了 SweetAlert,但Notify的灵活性意味着您可以轻松地与任何JavaScript警报解决方案一起使用。
许可证
Laravel Notify 在MIT许可证下发布。享受吧!