abhi-conceptlz / livewire-toast
Livewire v3 包用于显示 Toast 通知
v1.0
2024-02-08 06:48 UTC
Requires (Dev)
- livewire/livewire: ^3.0
- orchestra/testbench: ^8.21
README
基于 TALL Stack 的 Livewire v3 包用于显示 Toast 通知。
需求
请确保您的项目已正确安装 Livewire。
请确保您的项目已正确安装 TailwindCSS。
请确保您的项目已正确安装 AlpineJS。
安装
您可以使用 Composer 安装此包。
composer require abhi-conceptlz/livewire-toast
使用方法
将 Livewire 组件 @livewire('livewire-toast')
放入您的应用布局中的任何位置。
然后您可以按照以下方式调用 Livewire Toast
从 Livewire 组件
$this->emitTo('livewire-toast', 'show', 'Project Added Successfully'); //Will show Success Message $this->emitTo('livewire-toast', 'showError', 'There was an Error!'); //Will show error. showError, showWarning, showInfo, showSuccess are supported $this->emitTo('livewire-toast', 'show', ['type' => 'warning', 'message' => 'This is warning!']); //Can also pass type and message as array
使用 Session Flash
session()->flash('livewire-toast', 'Project Added Successfully'); session()->flash('livewire-toast', ['type' => 'error', 'message' => 'There was an Error!']);
从 Livewire 视图
$emitTo('livewire-toast', 'show', 'Project Added Successfully'); //Will show Success Message $emitTo('livewire-toast', 'showError', 'There was an Error!'); //Will show error. showError, showWarning, showInfo, showSuccess are supported $emitTo('livewire-toast', 'show', {'type' : 'warning', 'message' : 'This is warning!'}); //Can also pass type and message as object
从 JS
Livewire.emitTo('livewire-toast', 'show', 'Project Added Successfully'); //Will show Success Message Livewire.emitTo('livewire-toast', 'showError', 'There was an Error!'); //Will show error. showError, showWarning, showInfo, showSuccess are supported Livewire.emitTo('livewire-toast', 'show', {'type' : 'warning', 'message' : 'This is warning!'}); //Can also pass type and message as object
配置
如果您想覆盖配置,您必须使用以下命令发布资源
php artisan vendor:publish --tag=config
这将发布配置文件到 config/livewire-toast.php
。您可以覆盖任何配置。
您还可以使用以下命令发布视图
php artisan vendor:publish --tag=views
这将发布 resources/views/vendor/livewire-toast
目录中的视图,您可以根据需要进行自定义。
故障排除
当使用 TailwindCss 时,您的消息没有样式?请发布您的视图。因此 Laravel Mix 编译器将找到包相关的视图,并相应地清除 CSS。
贡献
欢迎拉取请求。对于重大更改,请先打开一个问题来讨论您希望进行更改的内容。