Echo development

From relaticle/relaticle · View interactive version

Echo development is an AI agent skill from the GitHub repository relaticle/relaticle. Develops real-time broadcasting with Laravel Echo. Activates when setting up broadcasting (Reverb, Pusher, Ably); creating ShouldBroadcast events; defining broadcast channels (public, private, presence, encrypted); authorizing channels; configuring Echo; listening for events; implementing client eve

How to use this skill

Skill file

Laravel Broadcasting & Echo

When to Apply

Activate this skill when:

Documentation

Use search-docs for detailed broadcasting patterns and documentation.

Basic Usage

Installing Broadcasting

php artisan install:broadcasting

Use flags for specific drivers: --reverb, --pusher, --ably. This creates config/broadcasting.php and routes/channels.php.

Creating a Broadcast Event

php artisan make:event OrderShipped

<!-- Broadcast Event -->

namespace App\Events;

use App\Models\Order;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Queue\SerializesModels;

class OrderShipped implements ShouldBroadcast
{
    use InteractsWithSockets, SerializesModels;

    public function __construct(public Order $order) {}

    public function broadcastOn(): array
    {
        return [new PrivateChannel('orders.'.$this->order->id)];
    }
}

Dispatch the event:

<!-- Dispatch Event -->

use App\Events\OrderShipped;

OrderShipped::dispatch($order);

Authorizing Channels

Define authorization in routes/channels.php:

<!-- Channel Authorization -->

use App\Models\Order;
use App\Models\User;

Broadcast::channel('orders.{orderId}', function (User $user, int $orderId) {
    return $user->id === Order::findOrNew($orderId)->user_id;
});

Create a channel class for complex authorization:

php artisan make:channel OrderChannel

List all registered channels:

php artisan channel:list

Client-Side Setup

Install Echo and Pusher JS:

npm install --save-dev laravel-echo pusher-js

<!-- Echo Client Configuration -->

import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;

window.Echo = new Echo({
    broadcaster: 'reverb',
    key: import.meta.env.VITE_REVERB_APP_KEY,
    wsHost: import.meta.env.VITE_REVERB_HOST,
    wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
    wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
    forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? 'https') === 'https',
    enabledTransports: ['ws', 'wss'],
});

Listening for Events

<!-- Listen on Private Channel -->

Echo.private(`orders.${orderId}`)
    .listen('OrderShipmentStatusUpdated', (e) => {
        console.log(e.order);
    });

Running Required Processes

php artisan queue:work    # Required for ShouldBroadcast events
php artisan reverb:start  # Required for Reverb driver

What's Possible

Use search-docs to find detailed code examples and configuration for each of these:

Channel Types

Event Customization

Broadcasting Interfaces

Broadcasting Helpers

Channel Authorization

Model Broadcasting

Client-Side Features

Common Pitfalls

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.