damisadam / notify
Laravel 的灵活闪存通知
1.0
2021-12-30 05:15 UTC
Requires
- php: >=5.4.0
- illuminate/support: ~5.0
This package is not auto-updated.
Last update: 2024-09-20 16:20:06 UTC
README
安装
使用 Composer
composer require damisadam/notify
将服务提供者添加到 config/app.php
Codecourse\Notify\NotifyServiceProvider::class,
如果需要,您还可以在 config/app.php
中包含 Facade。
'Notify' => Codecourse\Notify\Facades\Notify::class,
注意,有一个可用的 notify() 函数,所以除非您真的想使用 Facade,否则不需要包含它。
使用方法
基本使用
从您的应用程序中,调用带消息和类型的 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 弹出解决方案一起使用。
问题和贡献
只需通过 GitHub 提交问题或拉取请求。谢谢!