helmesvs / laravel-notify
使用 Toastr 或 PNotify 为 Laravel 提供优雅的通知
v1.1.0
2017-10-17 18:45 UTC
Requires
- php: >=5.4.0
- illuminate/session: >=5.0.0
- illuminate/support: >=5.0.0
This package is not auto-updated.
Last update: 2024-09-28 06:04:26 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 的文档。