Answer the question
In order to leave comments, you need to log in
larvel+vue chat (laravel-echo-server [socket.io])?
Kind.
I want to write a chat, I use laravel-echo-server (socket.io)
In vue via axios, I send a message
to the controller, in the controller I call ChatEvent::dispatch( $request->input('message') )
in the event I write to a variable and call Chanel('chat')
in vue I'm listening to port 6001 and when the event fires, the code inside should work, but it doesn't work
EVENT
public $message;
public function __construct($message)
{
$this->message = $message;
}
public function broadcastOn()
{
return new Channel('chat');
}
public function broadcastAs()
{
return 'ChatEvent';
}
import Echo from 'laravel-echo';
window.io = require('socket.io-client')
if (typeof io !== 'undefined') {
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
});
} else{
console.log('errors socket.io, => bootstrap.js line 33')
}
mounted()
window.Echo.channel('chat')
.listen('ChatEvent', (e) =>
{
console.log(123)
})
},
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question