aliowa/livewire-toasts

Laravel Livewire toast 通知使用 Alpine JS

v1.0.0 2021-12-17 15:26 UTC

This package is auto-updated.

Last update: 2024-09-17 21:23:49 UTC


README

此包允许您通过 Laravel Livewire 组件动态显示 toast 通知。Toast 由 AlpineJS 驱动,无延迟显示。

文档

要求

  • AlpineJS 版本 3.0 或更高

安装

您可以通过 composer 安装此包

composer require aliowa/livewire-toasts

x-aliowa-livewire-toasts 组件添加到您的应用布局视图中

<body>
  <!-- body here -->
  
  <x-aliowa-livewire-toasts />
</body>

默认情况下,toast 使用 TailwindCSS 样式化。要自动发现必要的类,可以发布 toast 视图或将包视图位置添加到您的 tailwind.config.js 文件中

module.exports = {
    content: [
        './vendor/aliowa/**/views/**/*.blade.php',
    ],

使用

Livewire 组件设置

Toastable 特性添加到您的 Livewire 组件中

<?php

namespace App\Http\Livewire;

use Aliowa\LivewireToasts\Traits\Toastable;
use Livewire\Component;

class SavePost extends Component
{
    use Toastable;

    //component code
}

显示 Toast

通过提供消息并调用其中一个四个方法 toastSuccesstoastWarningtoastDangertoastInfo 来显示 toast

public function savePost()
{
    $this->toastSuccess('Post has been successfully saved!');

    $this->toastWarning('You have reached the daily post limit!');

    $this->toastDanger('Post has not been saved!');

    $this->toastInfo('A confirmation email has been sent');
}

发布资产

自定义视图

默认情况下,toast 视图文件使用 TailwindCSS,但您可以通过发布和更改来定制网站上的 toast 样式。

php artisan vendor:publish --tag=aliowa-livewire-toasts:views

现在编辑视图文件 resources/views/vendor/components/aliowa/livewire-toasts/components/toasts.blade.php。该包将使用此视图来渲染组件。