helmesvs/laravel-notify

使用 Toastr 或 PNotify 为 Laravel 提供优雅的通知

v1.1.0 2017-10-17 18:45 UTC

This package is not auto-updated.

Last update: 2024-09-28 06:04:26 UTC


README

使用 ToastrPNotify 为 Laravel 提供优雅的通知

alt text

安装

  1. 运行 composer require helmesvs/laravel-notify 或者在 composer.jsonrequire 键中添加 "helmesvs/laravel-notify" 并运行 composer install
  2. Helmesvs\Notify\NotifyServiceProvider::class, 添加到 config/app.php 文件的 providers 键中。
  3. 'Notify' => Helmesvs\Notify\Facades\Notify::class, 添加到 config/app.php 文件的 aliases 键中。
  4. 运行 php artisan vendor:publish --provider="Helmesvs\Notify\NotifyServiceProvider" --tag="notify" 以发布配置文件。
  5. 将输出 {!! Notify::render() !!} 包含在您的母版视图模板中。
  6. 可选: 修改位于 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.jspnotify 以使用 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 的文档。