Certainly! Based on your environment variables, you’re trying to use Laravel Herd’s Reverb as your broadcast driver. Here’s a checklist and example setup to ensure everything works when you dispatch an event like AuditCompleted::dispatch($audit);.
1. Check Your .env Configuration
Your environment variables look correct. Make sure you have:
BROADCAST_CONNECTION=reverb
REVERB_APP_ID=1001
REVERB_APP_KEY=laravel-herd
REVERB_APP_SECRET=secret
REVERB_HOST="reverb.herd.test"
REVERB_PORT=443
REVERB_SCHEME=https
VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"
2. BroadcastServiceProvider
Ensure you have the BroadcastServiceProvider registered in config/app.php (it is by default in Laravel).
3. Event Should Broadcast
Your event should implement ShouldBroadcast. Example:
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class AuditCompleted implements ShouldBroadcast
{
use InteractsWithSockets;
public $audit;
public function __construct($audit)
{
$this->audit = $audit;
}
public function broadcastOn()
{
return new PrivateChannel('audits');
}
}
4. Broadcasting Config
In config/broadcasting.php, ensure you have the reverb connection:
'reverb' => [
'driver' => 'reverb',
'key' => env('REVERB_APP_KEY'),
'secret' => env('REVERB_APP_SECRET'),
'app_id' => env('REVERB_APP_ID'),
'host' => env('REVERB_HOST', '127.0.0.1'),
'port' => env('REVERB_PORT', 443),
'scheme' => env('REVERB_SCHEME', 'https'),
'options' => [
'useTLS' => env('REVERB_SCHEME', 'https') === 'https',
],
],
5. Front-End Setup
If you’re using Laravel Echo with Vite, in your resources/js/bootstrap.js or similar:
import Echo from 'laravel-echo';
window.Echo = new Echo({
broadcaster: 'reverb',
key: import.meta.env.VITE_REVERB_APP_KEY,
host: import.meta.env.VITE_REVERB_HOST,
port: import.meta.env.VITE_REVERB_PORT,
scheme: import.meta.env.VITE_REVERB_SCHEME,
forceTLS: import.meta.env.VITE_REVERB_SCHEME === 'https',
});
6. Dispatching the Event
When you run:
AuditCompleted::dispatch($audit);
Make sure the queue worker is running if your event is queued:
php artisan queue:work
7. Testing
- Open your browser’s console and check for any Echo connection errors.
- Make sure the Reverb server is running (Herd should handle this).
- Check
storage/logs/laravel.logfor any broadcasting errors.
Summary:
- Double-check
.envandconfig/broadcasting.php - Event must implement
ShouldBroadcast - Front-end Echo config must use Vite env variables
- Queue worker must be running if events are queued
If you have a specific error message, please share it for more targeted help!