osp-pawan / pusherbyrepository
这将通过仓库使用Pusher发送通知
1.0.1
2021-03-26 08:05 UTC
Requires
- pusher/pusher-php-server: ^6.1
This package is auto-updated.
Last update: 2024-09-26 15:50:12 UTC
README
此包将帮助您通过仓库模式代码使用Pusher发送通知
安装
$ composer require osp-pawan/pusherbyrepository
服务提供者 & Facade(Laravel 5.5+可选)
在您的 config/app.php 文件中注册提供者和外观。
'providers' => [ ..., OspPawan\PusherByRepository\PusherByRepositoryServiceProvider::class, //Uncomment below line from your `config/app.php` App\Providers\BroadcastServiceProvider::class, ]
环境变量文件更改
当Composer完成安装后,我们需要配置Laravel使用Pusher作为其广播驱动,为此,打开您的Laravel安装根目录下的 .env 文件。更新以下配置对应的值
BROADCAST_DRIVER=pusher // Get the credentials from your pusher dashboard PUSHER_APP_ID=XXXXX PUSHER_APP_ID=XXXXX PUSHER_APP_KEY=XXXXXXX PUSHER_APP_SECRET=XXXXXXX
简单示例
为了使用PusherRepository,必须使用以下构造函数
<?php use OspPawan\PusherByRepository\PusherRepository; private $pusherRepository; public function __construct(PusherRepository $pusherRepository){ $this->pusherRepository = $pusherRepository; }
在函数中使用以下行发送广播通知给所有用户
$this->pusherRepository->broadcastNotification('Send you message here');
发送广播通知后,您可以在以下位置查看所有通知:运行 php artisan serve --port=8001 并打开 http://127.0.0.1:8001/test-pusher