祝你今天愉快!
我有一个问题:我设置了Laravel & Pusher,但是遇到了这个错误,没有办法解决:

我检查了我的应用键,应用程序集群,但是都是正确的。
有人能帮我吗?
app.js
const app = new Vue({
el: '#app',
data: {
messages: []
},
methods:{
addMessage(message){
this.messages.push(message);
axios.post('/messages', message).then(response => {
console.log(response);
});
}
},
created(){
axios.get('/messages').then(response => {
this.messages = response.data;
});
Echo.channel('chatroom')
.listen('MessageEvent', (e) => {
console.log(e);
});
}
})bootstrap.js
import Echo from 'laravel-echo'
window.Pusher = require('pusher-js');
window.Echo = new Echo({
broadcaster: 'pusher',
key: '************',
cluster: 'ap1',
encrypted: false
});MessageEvent
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message, $user;
public function __construct(Message $message, User $user)
{
$this->message = $message;
//query
$this->user = $user;
}
public function broadcastOn()
{
return new PresenceChannel('chatroom');
}channels.php
Broadcast::channel('App.User.{id}', function ($user, $id) {
return (int) $user->id === (int) $id;
});
Broadcast::channel('chatroom', function ($user, $id) {
return $user;
});发布于 2018-05-18 07:17:09
错误403或500 /广播/auth与Laravel版本> 5.3 & Pusher,您需要用resources/assets/js/bootstrap.js修改您的代码
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'your key',
cluster: 'your cluster',
encrypted: true,
auth: {
headers: {
Authorization: 'Bearer ' + YourTokenLogin
},
},
});而在app/Providers/BroadcastServiceProvider.php中
Broadcast::routes()使用
Broadcast::routes(['middleware' => ['auth:api']]);或
Broadcast::routes(['middleware' => ['jwt.auth']]); //if you use JWT它对我有用,希望它能帮助你。
发布于 2019-07-10 08:54:41
删除$id,因为您没有从事件中传递
Broadcast::channel('chatroom', function ($user) {
return true;
});发布于 2018-03-26 12:56:52
我认为,如果您使用了laravel,只要使用goto /assets/js/bootstrap.js,就需要给出一个真实的观点。
只需在窗口中添加下面一行
Echo = new Echo({
authEndpoint : 'http://localhost/projectName/public/broadcasting/auth',
});https://stackoverflow.com/questions/48615342
复制相似问题