Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Echo from 'laravel-echo'
- window.Pusher = require('pusher-js');
- window.Echo = new Echo({
- broadcaster: 'pusher',
- key: '....',
- });
- window.Echo.channel('chat-room')
- .listen('.app.Events.ChatMessageWasReceived.php', (e)=>{
- console.log(e);
- });
- class ChatMessageWasReceived implements ShouldBroadcast
- {
- use Dispatchable, InteractsWithSockets, SerializesModels;
- public $chatMessage;
- public $user;
- /**
- * Create a new event instance.
- *
- * @param $user
- * @param $chatMessage
- */
- public function __construct($chatMessage, $user)
- {
- $this->user = $user;
- $this->chatMessage = $chatMessage;
- }
- /**
- * Get the channels the event should broadcast on.
- *
- * @return IlluminateBroadcastingChannel|array
- */
- public function broadcastOn()
- {
- return new Channel('chat-room');
- }
- }
Add Comment
Please, Sign In to add comment