f1uder / laravel-notification
Laravel Livewire 通知 (+ AlpineJS)
1.2.1
2023-05-19 17:30 UTC
Requires
- php: ^8.0|^8.1
- illuminate/support: ^8.0|^9.0|^10.0
- laravel/framework: ^8.0|^9.0|^10.0
- livewire/livewire: ^2.3|^v2.10
Requires (Dev)
- laravel/pint: ^1.0
This package is auto-updated.
Last update: 2024-09-19 20:38:42 UTC
README
安装
您可以通过 composer 安装此包
composer require f1uder/laravel-notification
使用以下命令发布配置文件
php artisan vendor:publish --tag="laravel-notification"
添加 CSS 文件(notification.css)
@import "../../public/vendor/laravel-notification/css/notification.css"; @tailwind base; @tailwind components; @tailwind utilities;
将代码添加到模板中,在 body 标签之后
<body> <livewire:laravel-notification.notice/> ... </body>
Laravel 使用方法
return redirect('/')->notice('message text', 'alert');
return redirect()->route('home')->notice('message text', 'info');
Livewire 组件使用方法
$this->notice('message text', 'alert');
return redirect('/')->notice('message text', 'alert');
AlpineJS 使用方法
$dispatch('notice', {message: 'message text', type: 'alert'});
参数
使用方法:notice($message, $type, $timer, $title)
$message
- 消息。$type
- 通知类型。alert
info
- 默认success
$timer
- 3000 默认 = 3 秒。$title
- 通知标题。默认 = null。
配置
config/notification.php
$timer
- 通知显示时间(秒)。$position
- 通知位置。tr
- 右上角(默认)。tl
- 左上角。br
- 右下角。bl
- 左下角。
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。