Realtime WebSocket Notifications for Laravel
Trigger real-time WebSocket events from Laravel controllers, jobs, and queued tasks. Zero-dependency PHP SDK — no Guzzle, no Reverb, no Echo server to configure or maintain.
composer require apinator/apinator-php Server npm install @apinator/client Client Laravel's broadcast system is powerful but traditionally requires a separate WebSocket server — Laravel Reverb, Echo Server, or a Pusher subscription. Apinator gives you real-time WebSocket notifications from any Laravel controller, queued job, or listener with a simple API call. No additional server process, no Echo server to configure, and no infrastructure to manage.
Quick Start
How to add WebSocket notifications to Laravel
Add realtime features to your Laravel app in a few steps.
See your first event (no backend)
Before writing any PHP: open apinator.io/try/?key=YOUR_APP_KEY&cluster=us, or run this snippet in your Laravel frontend, then click the Send test event button on your app's Overview page in the dashboard. my-channel is a public channel, so nothing needs a server or an auth endpoint yet. Open the dashboard
// resources/js/app.js (npm install @apinator/client)
import { Apinator } from '@apinator/client'
const client = new Apinator({ appKey: 'YOUR_APP_KEY', cluster: 'us' }).connect()
client.subscribe('my-channel').bind('my-event', (data) => {
console.log('Received:', data)
}) Install the PHP SDK
Add the server SDK via Composer. Zero dependencies — pure PHP 8.1+.
composer require apinator/apinator-php Initialize in a service provider
Register the Apinator client as a singleton in your Laravel service container. Add an apinator entry (app_id, key, secret, cluster) to config/services.php that reads from your .env.
// app/Providers/AppServiceProvider.php
use Apinator\Apinator;
public function register(): void
{
$this->app->singleton(Apinator::class, fn () =>
new Apinator(
appId: config('services.apinator.app_id'),
key: config('services.apinator.key'),
secret: config('services.apinator.secret'),
cluster: config('services.apinator.cluster')
)
);
} Trigger WebSocket events from a controller
Publish real-time WebSocket events from any Laravel controller or queued job. All subscribed browser clients receive the notification instantly.
public function store(Request $request, Apinator $apinator)
{
$order = Order::create($request->validated());
$apinator->trigger(
name: 'new-order',
data: json_encode(['id' => $order->id]),
channel: 'private-orders'
);
} Add a WebSocket channel auth route
Create a POST route that authenticates private WebSocket channel subscriptions using HMAC-SHA256 signing.
// routes/api.php
Route::post('/realtime/auth', function (Request $request, Apinator $apinator) {
$auth = $apinator->authenticateChannel(
$request->input('socket_id'),
$request->input('channel_name')
);
return response()->json($auth);
}); Why Laravel
Built for Laravel developers
Zero Dependencies
Pure PHP 8.1+ — no Guzzle, no cURL wrappers. Uses native stream context for HTTP requests.
Service Container Ready
Register as a singleton and inject via constructor. Follows Laravel dependency injection conventions.
Queue Compatible
Trigger events from Laravel queued jobs, listeners, and scheduled tasks. Works anywhere PHP runs.
Channel Introspection
List active channels and read subscriber counts with getChannels() and getChannel() for admin views and monitoring.
How WebSocket notifications work in a Laravel application
Laravel's traditional broadcasting system — Laravel Echo combined with a WebSocket server like Reverb or the older Laravel Echo Server — requires running a persistent WebSocket process alongside your web application. This adds operational complexity: a separate server to deploy, monitor for crashes, scale independently, and keep in sync with your Laravel authentication.
Apinator removes this complexity. Your Laravel application calls the Apinator SDK from a controller, job, or listener — a single method call that publishes a real-time WebSocket event to all subscribed browser clients. Apinator's infrastructure maintains the persistent WebSocket connections. Your Laravel server stays stateless and doesn't hold any WebSocket connections, which simplifies horizontal scaling behind a load balancer.
The PHP SDK has zero dependencies and uses PHP's native stream contexts for HTTP requests — no Guzzle version to pin, no Composer conflicts, and no compatibility issues across PHP 8.1+ versions. It works equally well in controllers, Queued Jobs, Artisan commands, scheduled tasks, and Laravel Listeners.
Full Example
Full Example: Realtime WebSocket Notifications in a Laravel Controller
Complete WebSocket example: Laravel service provider setup, controller for triggering real-time events, auth route for private channels, and a JavaScript frontend.
namespace App\Http\Controllers;
use App\Models\Order;
use Illuminate\Http\Request;
use Apinator\Apinator;
class OrderController extends Controller
{
public function __construct(
private readonly Apinator $apinator
) {}
public function store(Request $request)
{
$order = Order::create($request->validated());
$this->apinator->trigger(
name: 'new-order',
data: json_encode([
'id' => $order->id,
'total' => $order->total,
]),
channel: 'private-orders'
);
return response()->json($order, 201);
}
}Related Docs
Read the core WebSocket guides
Related Use Cases
Explore realtime use cases
From the blog
How to Add Realtime to a Laravel App
Add WebSocket-powered realtime features to your Laravel application — publishing events from controllers and subscribing from the frontend with a few lines of code.
Presence Channels Explained
Presence channels let you track who's online in real time — showing typing indicators, viewer counts, and live cursors without building your own member tracking.
What Is a WebSocket?
WebSockets let servers push data to clients the moment it changes — no polling, no waiting. Here's how they work, what they're good for, and when to use them.
Start building realtime Laravel apps
Completely free. No credit card. No catch.