rai/notify

修改自 Codecourse/notify

dev-main 2023-05-13 12:41 UTC

This package is not auto-updated.

Last update: 2024-09-28 13:15:16 UTC


README

Notify

安装

使用 Composer

composer require rai/notify

将服务提供者添加到 config/app.php

Rai\Notify\NotifyServiceProvider::class,

如果需要,可以选择性地在 config/app.php 中包含 Facade。

'Notify' => Rai\Notify\Facades\Notify::class,

注意,存在一个 notify() 函数,所以除非你确实想使用 Facade,否则无需包含它。

用法

基本用法

从你的应用程序中,调用带有消息和类型的 flash 方法。

notify()->flash('Welcome back!', 'success');

在视图中,你现在可以检查是否存在 flash 消息并将其输出。

@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 example

上面的示例使用了 SweetAlert,但 Notify 的灵活性意味着你可以轻松地与任何 JavaScript 弹窗解决方案一起使用。

问题和贡献

只需通过 GitHub 提交问题或拉取请求。谢谢!