ably/ably-php-laravel
Official Ably integration for Laravel. Adds an Ably broadcasting driver plus helpers for realtime pub/sub, presence, and token authentication, letting Laravel apps push live events to web and mobile clients over Ably’s globally distributed network.
composer require ably/ably-php-laravel. Laravel's package auto-discovery registers Ably\Laravel\AblyServiceProvider and the Ably facade alias, so no manual config/app.php edits are needed on Laravel 5.5+.php artisan vendor:publish --provider="Ably\Laravel\AblyServiceProvider" (or --tag=config). This creates config/ably.php.ABLY_KEY in .env using the full key string from your Ably dashboard: appId.keyId:keySecret. This is the single credential the package reads; there is no separate app-id setting to configure.config/ably.php and at the service provider's container binding — the package is thin, essentially a singleton wrapper around Ably\AblyRest. Once you understand that binding, the rest of the API is the ably-php REST client, so the upstream ably-php docs are your real reference.use Ably\Laravel\Facades\Ably;
Ably::channel('orders')->publish('created', ['id' => $order->id]);
php artisan tinker call to Ably::time() — if that returns a timestamp, your key and network path are good and any remaining problem is channel/permission related.DB::afterCommit() so you never announce a message for a transaction that rolls back.ShouldQueue job rather than inline. This keeps request latency off the Ably round trip and gives you retries. Combine with ShouldBeUnique or a rate limiter to avoid flooding a channel during bulk operations.Route::get('/ably/auth', function () {
return response()->json(
Ably::auth()->createTokenRequest(['clientId' => auth()->id()])
);
});
Scope the capability per channel (subscribe only, or publish for trusted clients) rather than granting blanket access.
private-user.{id}, presence-room.{roomId}, org.{orgId}.events up front. The capability strings in your token endpoint must match these patterns exactly; retrofitting a naming scheme later means touching every auth rule.ably broadcast driver (which also uses ably/ably-php) is usually the better fit — you get ShouldBroadcast events for free. Reach for this package's facade when you need direct REST control: presence queries, channel history, token requests, or publishing from non-broadcast contexts like console commands and webhooks.Ably::channel($c)->presence->get() in dashboards and ->history() for backfill/replay endpoints, keeping in mind history is bounded by your account's retention settings.AblyPublisher interface around the facade and inject that. It makes the package swappable and, more importantly, testable — see below.app()->instance() / a small factory rather than mutating the single bound client at runtime.Broadcast::driver('ably'); that lives in the framework. Configuring BROADCAST_DRIVER=ably and expecting this package to handle it is a common first-day confusion.AblyRest, not a realtime websocket client. There is no server-side subscribe callback here — inbound events must be consumed in the browser/JS client or via Ably's webhook/queue integrations. Design your architecture around that early.ABLY_KEY in production, run php artisan config:cache (and config:clear locally). A stale cached key produces auth errors that look like a wrong credential.: or a key pasted with surrounding quotes surfaces as an AblyException at first call, not at boot. The package does no validation of the key at registration time — fail fast with your own boot-time check if a misconfiguration would be costly.AblyRest into the container in a test case, or (preferred) depend on your own wrapper interface and fake that. If you must assert on publish calls, a Mockery::mock(AblyRest::class) swapped via $this->app->instance() is the least invasive route.Ably\Exceptions\AblyException with a code. Catch it in publish paths and decide whether a failed publish should fail the surrounding job — for user-triggered actions, swallowing and logging is often correct; for audit-style events, let it retry.ably/ably-php in composer.json if you need to control when SDK changes land, and check upstream release notes when bumping, since this package's own changelog won't mention them.host, proxy, httpOptions, longer timeouts), rebind Ably\AblyRest in your own AppServiceProvider and the facade will resolve your instance — cleaner than post-hoc mutation of the singleton.How can I help you explore Laravel packages today?