laravel - 如何在 Laravel Echo 中从 Pusher 发出广播通知
问题描述
根据我的情况,当用户向数据库添加空缺时,我正在尝试使用 Laravel Echo 侦听器从推送器发出 Laravel 广播通知。我不需要使用 vue.js 在默认通知栏上显示通知。只是我需要在某些用户向数据库添加空缺时发出警报。但不幸的是,我无法弄清楚。有没有办法做到这一点?
这是我的通知类
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\BroadcastMessage;
use App\Employer;
use App\Vacancy;
class vacancyAdd extends Notification
{
use Queueable;
public $vacancy;
public function __construct($vacancy)
{
$this->vacancy = $vacancy;
}
public function via($notifiable)
{
return ['database','broadcast'];
}
public function toDatabase($notifiable)
{
return [
'vacancy' => $this->vacancy
];
}
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'vacancy' => $this->vacancy
]);
}
}
这是我的 app.js
require('./bootstrap');
window.Vue = require('vue');
/**
* Next, we will create a fresh Vue application instance and attach it to
* the page. Then, you may begin adding components to this application
* or customize the JavaScript scaffolding to fit your unique needs.
*/
Vue.component('ExampleComponent', require('./components/ExampleComponent.vue'));
const app = new Vue({
el: '#app',
created(){
Echo.private('App.User.'+window.Laravel.userId).notification((notification) => {
console.log('Notification received ', notification);
alert(notification);
});
}
});
我的 Pusher 调试控制台
Pusher Debug Screenshot 你能帮我摆脱这个吗?
解决方案
推荐阅读
- python - 为什么这个 Kivy 应用程序崩溃而没有任何逻辑错误
- svg - 如何定位一个元素相对于svg中的其他元素
- excel - 将特定单词更改为阿拉伯字符,包括字符“ー”
- jquery - 如何在 ajax 中使用复选框?
- webpack - Elixir phoenix中添加资产的最佳方法
- android - google play 将应用转移到另一个帐户的交易 ID
- java - 在 Jboss 中找不到 com.sun.jdi
- python - 如何从不同页面抓取数据并分配给同一个数据集?
- lisp - 如何在 AutoLisp 中访问带引号的变量数据?
- python - 为什么 X = np.array() 在不同的场合返回一个大小为 (N, 1) 和 (N,) 的数组?