qdev1000 / laravel-notify
使用 Toastr 或 PNotify 为 Laravel 提供优雅的通知
dev-master
2021-01-07 02:10 UTC
Requires
- php: >=5.4.0
- illuminate/session: >=5.0.0
- illuminate/support: >=5.0.0
This package is auto-updated.
Last update: 2024-09-26 00:39:06 UTC
README
使用 Toastr 或 PNotify 为 Laravel 提供优雅的通知
安装
- 运行
composer require helmesvs/laravel-notify
或在composer.json
中的require
键添加"helmesvs/laravel-notify"
并运行composer install
。 - 将
Helmesvs\Notify\NotifyServiceProvider::class,
添加到config/app.php
中的providers
键。 - 将
'Notify' => Helmesvs\Notify\Facades\Notify::class,
添加到config/app.php
中的aliases
键。 - 运行
php artisan vendor:publish --provider="Helmesvs\Notify\NotifyServiceProvider" --tag="notify"
来发布配置文件。 - 在您的母版视图模板中包含输出
{!! Notify::render() !!}
。 - 可选:修改位于 config/notify.php 的配置文件。
使用
在您的控制器中调用以下方法之一以插入通知
Notify::warning($message, $title = null, $options = [])
- 添加警告通知Notify::error($message, $title = null, $options = [])
- 添加错误通知Notify::info($message, $title = null, $options = [])
- 添加信息通知Notify::success($message, $title = null, $options = [])
- 添加成功通知Notify::add($type: warning|error|info|success, $message, $title = null, $options = [])
- 添加通知Notify::clear()
- 清除所有当前通知
配置
打开 config/notify.php
以调整包配置。如果此文件不存在,运行 php artisan vendor:publish --provider="Helmesvs\Notify\NotifyServiceProvider" --tag="notify"
以创建默认配置文件。
通用选项
'options' => [ 'lib' => 'toastr', 'style' => 'custom' ]
将 'lib'
设置为 toastr
以使用 toastr.js 或 pnotify
以使用 pnotify.js。
将 'style'
设置为 'custom'
以使用自定义设置,或设置为 'default'
以使用库默认设置。
通知样式可以在 public/vendor/Notify/style.css
中自定义。
Toastr 选项
'ToastrOptions' => [ "closeButton" => false, "closeHtml" => '', "newestOnTop" => true, "progressBar" => false, ... ]
PNotify 选项
'PNotifyOptions' => [ 'title_escape' => false, 'text_escape' => false, 'styling' => 'brighttheme', 'addclass' => '', ... ]
有关可用选项的列表,请参阅 toastr.js 和 pnotify.js 的文档。