cornford / notifier
使用 AJAX 在 Laravel 中向客户端发送通知消息的简单方法。
Requires
- php: >=5.4.0
- illuminate/http: 5.*
- illuminate/routing: 5.*
- illuminate/session: 5.*
- illuminate/support: 5.*
- illuminate/view: 5.*
Requires (Dev)
- mockery/mockery: 0.9.1
- phpspec/phpspec: 2.0.*@dev
This package is auto-updated.
Last update: 2024-09-05 19:01:50 UTC
README
对于 Laravel 4.x,请查看 版本 1.0.1
将 Notifier 视为在 Laravel 中使用 AJAX 向客户端发送通知消息的简单方法。这包括
Notifier::notification
Notifier::none
Notifier::info
Notifier::success
Notifier::warning
Notifier::danger
Notifier::setOptions
Notifier::getOptions
Notifier::setNotifications
Notifier::getNotifications
Notifier::assets
Notifier::getDisplayNotifications
Notifier::displayNotifications
Notifier::displayedDisplayableNotifications
Notifier::displayedAllNotifications
Notifier::expireNotifications
Notifier::expireDisplayedNotifications
Notifier::expireAllNotifications
Notifier::fetchNotifications
Notifier::storeNotifications
Notifier::toArray
安装
首先通过 Composer 安装此软件包。编辑您的项目 composer.json
文件以要求 cornford/notifier
。
"require": {
"cornford/notifier": "1.*"
}
接下来,在终端中更新 Composer
composer update
此操作完成后,下一步是添加服务提供者。打开 app/config/app.php
,并在提供者数组中添加一个新项。
'Cornford\Notifier\Providers\NotifierServiceProvider',
下一步是引入外观。打开 app/config/app.php
,并在别名数组中添加一个新项。
'Notifier' => 'Cornford\Notifier\Facades\NotifierFacade',
然后我们需要通过运行以下命令引入配置文件、JavaScript 和 CSS。
php artisan vendor:publish --provider="Cornford\\Notifier\\Providers\\NotifierServiceProvider"
就这样!您已经准备就绪。
用法
使用方式与在 Controller / Model / 文件中使用逻辑类一样简单,您觉得合适即可
Notifier:
这将为您打开以下访问权限
- 通知
- 无
- 信息
- 成功
- 警告
- 危险
- 设置选项
- 获取选项
- 设置通知
- 获取通知
- 资产
- 获取显示通知
- 显示通知
- 已显示的显示通知
- 显示所有通知
- 过期通知
- 过期显示通知
- 过期所有通知
- 获取通知
- 存储通知
- 转换为数组
通知
notification
方法允许您创建通知,参数包括消息、类型和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::notification('This is a message', Notification::NOTIFICATION_TYPE_INFO, 0);
Notifier::notification('This is a message', Notification::NOTIFICATION_TYPE_NONE, new DateTime('tomorrow'));
无
none
方法允许您创建无通知,参数包括消息和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::none('This is a message', 0);
Notifier::none('This is a message', new DateTime('tomorrow'));
信息
info
方法允许您创建信息通知,参数包括消息和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::info('This is a message', 0);
Notifier::info('This is a message', new DateTime('tomorrow'));
成功
success
方法允许您创建成功通知,参数包括消息和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::success('This is a message', 0);
Notifier::success('This is a message', new DateTime('tomorrow'));
警告
warning
方法允许您创建警告通知,参数包括消息和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::warning('This is a message', 0);
Notifier::warning('This is a message', new DateTime('tomorrow'));
危险
danger
方法允许您创建危险通知,参数包括消息和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::danger('This is a message', 0);
Notifier::danger('This is a message', new DateTime('tomorrow'));
危险
danger
方法允许您创建危险通知,参数包括消息和过期时间,以分钟或 DateTime 对象的整数形式表示。
Notifier::danger('This is a message', 0);
Notifier::danger('This is a message', new DateTime('tomorrow'));
设置选项
setOptions
方法允许您使用选项数组参数设置当前 Notifier 选项集。
Notifier::setOptions(['option' => 'value']);
获取选项
getOptions
方法允许您以数组形式检索当前 Notifier 选项集。
$options = Notifier::getOptions();
设置通知
setNotifications
方法允许您使用通知对象数组设置当前通知集。
Notifier::setNotifications([new Notification('This is a message', Notification::NOTIFICATION_TYPE_NONE, new DateTime('now'), 1)]);
获取通知
getNotifications
方法允许您以通知对象数组形式检索当前通知集。
$notifications = Notifier::getNotifications();
资产
《assets》方法允许您将必要的通知资源包含到模板文件中,可选参数为类型。
{!! Notifier::assets() !!}
{!! Notifier::assets('cdn') !!}
获取显示通知
《getDisplayNotifications》方法允许您获取当前可显示的通知集合。
$notifications = Notifier::getDisplayNotifications();
显示通知
《displayNotifications》方法允许您标记传递的通知数组为已显示。
$notifications = Notifier::getNotifications();
Notifier::displayNotifications($notifications);
已显示的显示通知
《displayedDisplayableNotifications》方法允许您标记可显示的通知为已显示。
Notifier::displayedDisplayableNotifications();
显示所有通知
《displayedAllNotifications》方法允许您标记所有通知为已显示。
Notifier::displayedAllNotifications();
过期通知
《expireNotifications》方法允许您使传递的通知数组过期。
$notifications = Notifier::getNotifications();
Notifier::expireNotifications($notifications);
过期显示通知
《expireDisplayedNotifications》方法允许您使所有已显示的通知过期。
Notifier::expireDisplayedNotifications();
过期所有通知
《expireAllNotifications》方法允许您使所有通知过期。
Notifier::expireAllNotifications();
获取通知
《fetchNotifications》方法允许您从会话中获取所有通知。
Notifier::fetchNotifications();
存储通知
《storeNotifications》方法允许您将所有通知存储到会话中。
Notifier::storeNotifications();
转换为数组
《toArray》方法允许您将通知对象的数组转换为数组的数组。
$notifications = Notifier::getNotifications();
Notifier::toArray($notifications);
许可证
Notifier 是开源软件,遵循 MIT 许可证 许可。