asgardcms / notification-module
处理实时通知的模块
3.0.1
2017-10-11 08:14 UTC
Requires
- php: >=7.0.0
- composer/installers: ~1.0
- idavoll/core-module: ~3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.7
- orchestra/testbench: 3.5.*
- phpunit/phpunit: ~6.3
Suggests
- pusher/pusher-php-server: Allows notifications to enable real-time notifications.
README
快速向您的AsgardCms应用程序发送(实时)通知。
$this->notification->push('New subscription', 'Someone has subscribed!', 'fa fa-hand-peace-o text-green', route('admin.user.user.index'));
/** * Push a notification on the dashboard * @param string $title * @param string $message * @param string $icon * @param string|null $link */ public function push($title, $message, $icon, $link = null);
安装
模块下载
使用AsgardCMS的模块下载命令
php artisan asgard:download:module asgardcms/notification --migrations
这将下载模块并运行其迁移。
如果您想自定义字段、视图等,这是推荐的方式。
Composer
在您的终端中执行以下命令
composer require asgardcms/notification-module
注意:安装后,您需要在后端为博客模块页面分配所需的权限。
运行迁移
php artisan module:migrate notification
发布配置
php artisan module:publish-config notification
实时通知?
如果您想在WebSockets上实现实时通知,需要配置broadcasting.php
配置文件。完成后,将asgard.notification.config.real-time
选项设置为true
。
目前,Laravel broadcasting支持Pusher和Redis,但AsgardCms只有Pusher的前端集成。欢迎通过pull-request添加更多集成。查看Pusher集成以获取灵感。
要配置Pusher,您可以在.env
文件中添加以下行
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_ID=
PUSHER_APP_CLUSTER=us2
PUSHER_APP_ENCRYPTED=true
Pusher网站上应用程序的“入门”选项卡有一个.env
部分的区域。您可以直接复制并粘贴这些内容。
用法
用法简单直接
在需要的地方注入Modules\Notification\Services\Notification
接口并将其分配给类变量。
向登录用户发送通知
$this->notification->push('New subscription', 'Someone has subscribed!', 'fa fa-hand-peace-o text-green', route('admin.user.user.index'));
向特定用户发送通知
$this->notification->to($userId)->push('New subscription', 'Someone has subscribed!', 'fa fa-hand-peace-o text-green', route('admin.user.user.index'));