Skip to main content

Laravel Reverb WebSockets Implementation

Implement real-time features with Laravel Reverb including presence channels, private channels, client events, and scalable WebSocket broadcasting.

Fill in the placeholders

Edit the values, then copy your finished prompt.

Your Prompt
prompt.txt

                                

What this prompt does

This prompt makes the AI implement a real-time [feature_type] feature on Laravel Reverb, scoped by [concurrent_users] connections and [event_frequency] on Laravel [laravel_version]. It walks the full path: configuring Reverb and the Echo client, defining [event_count] broadcast events, wiring channel authorization, building the frontend listeners, adding client events, and scaling for production. Because you declare the connection count and event rate, the AI sizes payloads and scaling instead of producing a demo that only works for one user.

The structure works because real-time fails in the details this prompt forces you to specify. [max_payload_size] and [payload_limit] constrain message size; [event_list] and [channel_count] define the channels and their authorization via [auth_logic]; [client_event_limit] rate-limits whispers for typing indicators; and [process_manager], [horizontal_scaling], and [max_connections_per_user] cover supervised processes and multi-server scaling. The final step asks for tests using BroadcastFake and Event::fake() so the channels stay honest without a running server. Each broadcast event also gets a broadcastWith() payload trimmed under [payload_limit] and a choice between ShouldBroadcastNow and ShouldBroadcast based on how latency-sensitive that event is. Declaring [concurrent_users] and [event_frequency] is what lets the AI reason about message size and queueing instead of broadcasting everything synchronously, and the [reverb_transport] and [max_payload_size] settings keep the server configured for the traffic you actually expect.

When to use it

  • You are adding collaborative editing, live cursors, or presence to a Laravel app
  • You need presence channels that report who joined and left in real time
  • You want typing indicators or cursor sharing via client events with rate limiting
  • You expect hundreds of concurrent connections and must plan horizontal scaling
  • You want optimistic UI updates that reconcile against server confirmations
  • You need feature tests for broadcasting without standing up a live Reverb server

Example output

The AI returns step-by-step Laravel code: Reverb and broadcasting config, Echo client setup via Vite, a set of broadcast event classes with broadcastOn(), broadcastWith(), and broadcastAs(), channel routes in routes/channels.php with private and presence authorization, frontend Echo listeners with reconnection handling and a connection-status indicator, client-event whisper handling, a Supervisor and Redis pub/sub scaling plan, and feature tests using BroadcastFake.

Pro tips

  • Keep [payload_limit] well under [max_payload_size]; lean payloads are what hold up at [event_frequency]
  • Choose ShouldBroadcastNow only for latency-critical events — broadcasting everything synchronously can starve your workers
  • Set [client_event_limit] deliberately; unthrottled typing/cursor whispers flood the channel under load
  • Spell out [auth_logic] precisely so private and presence channels reject users who lack access
  • Use [max_connections_per_user] to account for multiple tabs and devices, not just one session
  • Lean on BroadcastFake and Event::fake() in tests — presence and client events are easy to break silently
  • Configure reconnection handling and a connection-status indicator early so dropped sockets recover instead of silently going stale
  • Match [max_payload_size] to your largest realistic event so the transport is not undersized for collaborative edits

Frequently Asked Questions

Can I test Reverb broadcasting without running the Reverb server?
Yes. The final step uses BroadcastFake and Event::fake() to assert event dispatching, channel authorization, and payload structure in tests. This keeps presence and client-event logic covered without standing up a live WebSocket server in CI.
How does it handle typing indicators and cursor sharing?
Those are built as client events (whispers) on the presence channel, with rate limiting set by `[client_event_limit]` events per second per user. The prompt asks for payload validation and the whisper/listenForWhisper pattern so ephemeral events do not hit your server unnecessarily.
Does it cover scaling Reverb across multiple servers?
It configures Reverb as a supervised process using `[process_manager]` and sets up `[horizontal_scaling]`, defaulting to Redis pub/sub across multiple Reverb instances behind a load balancer. It also caps connections per user via `[max_connections_per_user]`.
What is the difference between ShouldBroadcast and ShouldBroadcastNow here?
The prompt asks you to choose per event based on latency needs. ShouldBroadcastNow sends synchronously for time-sensitive events like cursor moves, while ShouldBroadcast queues the broadcast, which is fine for less urgent updates and easier on your workers under load.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

More in Laravel & PHP Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support