I’m trying to use Reverb to display updates after a form submission. In my blade file with the form, I added the following code.
setTimeout(() => {
console.log(window.Echo); // Check if Echo is defined
// Listening for the CommandExecuted event
window.Echo.channel('p-status')
.listen('TerminusCommandExecuted', (event) => {
console.log("event.message"); // Output the message to console
});
}, 200);
And my event file
<?php
namespace AppEvents;
use IlluminateBroadcastingChannel;
use IlluminateBroadcastingInteractsWithSockets;
use IlluminateContractsBroadcastingShouldBroadcast;
use IlluminateFoundationEventsDispatchable;
use IlluminateQueueSerializesModels;
class TerminusCommandExecuted implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public $message; // Property to hold the message
/**
* Create a new event instance.
*
* @param string $message
*/
public function __construct(string $message)
{
$this->message = $message; // Assign the message to the property
}
/**
* Get the channels the event should broadcast on.
*
* @return Channel
*/
public function broadcastOn(): Channel
{
// Return a single Channel instance instead of an array
return new Channel('p-status'); // Correctly returning a Channel instance
}
}
And in my job file that processes the form, I added the following
use AppEventsTerminusCommandExecuted;
event(new TerminusCommandExecuted($message));
Things that work.
From the blade file
console.log(window.Echo.channel(‘pantheon-status’) or just window.Echo
Using Tinker
new AppEventsTerminusCommandExecuted(‘Test message’);
However window.Echo.channel(‘p-status’).listen never fires. This is local development. I appreciate the help.