kapouet/laravel-notyf

在您的 Laravel 应用中添加 Notyf 支持

1.0.0 2021-03-06 16:49 UTC

This package is auto-updated.

Last update: 2024-09-07 00:33:00 UTC


README

Laravel Notyf banner

Latest Version on Packagist Total Downloads

在您的 Laravel 应用中添加 Notyf 支持。

安装

您可以通过 composer 安装此包

composer require kapouet/laravel-notyf

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Kapouet\Notyf\NotyfServiceProvider" --tag="kapouet:config"

配置文件结构类似于 Notyf,但使用 PHP,请参阅 https://github.com/caroso1222/notyf#api

使用方法

导入资产

<!-- For CSS -->
<x-notyf::styles/>

<!-- For JS -->
<!-- Import this script after Livewire if you use it -->
<xnotyf::scripts/>

使用 PHP 发送通知

Notyf::success('I\'m a success message');
Notyf::error('I\'m an error message');

// If you are added custom types in config file
// https://github.com/caroso1222/notyf#inotyfnotificationoptions
Notyf::message('custom', 'I\'m a custom message');

使用 Livewire 发送通知

use Kapouet\Notyf\Traits\Livewire\WithNotyf;
use Livewire\Component;

class MyComponent extends Component
{
    use WithNotyf;
    
    public function render(): string
    {
        return <<<'blade'
            <div>
                <button wire:click="toast">Toast me</button>
            </div>
        blade;
    }
    
    public function toast(): void
    {
        $this->notyfSuccess('I\'m a success message');
        $this->notyfError('I\'m an error message');

        // If you are added custom types in config file
        // https://github.com/caroso1222/notyf#inotyfnotificationoptions
        $this->notyfMessage('custom', 'I\'m a custom message');
    }
}

贡献

有关详细信息,请参阅 CONTRIBUTING

安全漏洞

请查看 我们的安全策略 了解如何报告安全漏洞。

致谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件