simtabi / larabell

Sweetalert 和 Toaster 通知,适用于 Laravel Livewire,支持 Tailwind 和 Bootstrap

dev-master 2023-03-13 19:54 UTC

This package is auto-updated.

Last update: 2024-09-26 03:26:12 UTC


README

banner

Larabell

Laravel Livewire 库,帮助您在应用程序中集成 SweetAlert 和 Toasts。

安装

composer require simtabi/larabell

如何使用

1. 在 config/app.php 中添加 LarabellServiceProvider

    ...
    \Simtabi\Larabell\LarabellServiceProvider::class
    ...

2. 包含 JavaScript

    ...
    // place this directive in the header
    @larabellCss

    // no need to call this, as it has already been called when you call @larabellScripts
    @larabellInit
    ...

3. 额外的配置文件

发布配置:php artisan vendor:publish --tag=larabell:assets。发布配置:php artisan vendor:publish --tag=larabell:config。发布配置:php artisan vendor:publish --tag=larabell:views

参见 可用配置

构建 Toast 和 SweetAlert

为了便于构建 Toast 和 SweetAlert,我们实现了链式方法来帮助您构建

Sweetalert

在您的组件中添加 Toast 特性。然后,在需要时调用 toast 方法。

use Simtabi\Larabell\HasLarabell;
use Livewire\Component;

class MyComponent extends Component
{
    use HasLarabell;

    public function save() {
        $this->fireSwalNotification();
    }

}

Sweetalert 参数

  • 标题
  • 图标:成功、错误、警告、信息、问题 - 默认为 信息
  • 超时:以毫秒为单位,默认为 5000

Toast

这是正常的 sweetalert 模态框。在您的组件中添加 Fire 特性。然后,在需要时调用 fire 方法。

use Simtabi\Larabell\HasLarabell;
use Livewire\Component;

class MyComponent extends Component
{
    use HasLarabell;

    public function save() {
        $this->fireToastNotification();
    }

}

Toast 参数

请参考在线文档: https://github.com/kamranahmedse/jquery-toast-plugin

致谢