Skip to content

Commit 586603e

Browse files
committed
+ docs/guides/laravel.md
1 parent 2946f3f commit 586603e

3 files changed

Lines changed: 91 additions & 1 deletion

File tree

docs/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AnyCable
22

3-
> A real-time server for Rails, Node.js, and Hotwire applications that runs on your servers and scales.
3+
> A real-time server for Rails, Laravel, Node.js, and Hotwire applications that runs on your servers and scales.
44
55
<picture>
66
<source srcset="/assets/images/logo_invert.svg" media="(prefers-color-scheme: dark)">
@@ -22,10 +22,14 @@ Make your real-time communication fast and [reliable](./anycable-go/reliable_str
2222

2323
- [Using AnyCable with Hotwire applications](guides/hotwire.md)
2424

25+
- [Using AnyCable with Laravel](guides/laravel.md)
26+
2527
- [Using AnyCable with other Ruby frameworks](ruby/non_rails.md)
2628

2729
## Latest updates 🆕
2830

31+
- **2025-05-30**: [Laravel support](guides/laravel.md)
32+
2933
- **2025-03-18**: [Presence tracking](./anycable-go/presence.md)
3034

3135
- **2024-10-08**: [File-based configuration (`anycable.toml`)](./anycable-go/configuration.md)

docs/_sidebar.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [Client-side usage](/guides/client-side.md)
1414
* [Using with JavaScript (serverless)](/guides/serverless.md)
1515
* [Using with Hotwire](/guides/hotwire.md)
16+
* [Using with Laravel](/guides/laravel.md)
1617
* [Broadcasting](/anycable-go/broadcasting.md)
1718
* [Signed streams](/anycable-go/signed_streams.md)
1819
* [Reliable streams](/anycable-go/reliable_streams.md)

docs/guides/laravel.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Using AnyCable with Laravel
2+
3+
<p class="preview-badge-header"></p>
4+
5+
AnyCable can be used as a WebSocket server for Laravel applications using Laravel Echo and Laravel Broadcasting capabilities. Consider it a drop-in replacement for Laravel Reverb, or Pusher, or whatever you use today.
6+
7+
Why choosing AnyCable over Reverb et al?
8+
9+
AnyCable is a battle-proofed real-time server that's been in production at scale for many years. It comes with extensive features set (reliability, various protocols support, observability tools, etc.) and it's **free to use**.
10+
11+
**NOTE:** Currently, this feature in the preview phase. There is some work in progress (see the limitations below).
12+
13+
## Getting Started
14+
15+
> Check out our demo Laravel application to see the complete example: [laravel-anycable-demo][]
16+
17+
First, install the [anycable-laravel][] library:
18+
19+
```sh
20+
composer require anycable-laravel
21+
```
22+
23+
Then, configure the application to use `anycable` broadcasting driver. For that, add the AnyCable service provider to the `bootstrap/providers.php` file:
24+
25+
```diff
26+
<?php
27+
28+
return [
29+
App\Providers\AppServiceProvider::class,
30+
// ...
31+
+ AnyCable\Laravel\Providers\AnyCableBroadcastServiceProvider::class,
32+
];
33+
```
34+
35+
Then, register the `anycable` driver in your `config/broadcasting.php` file:
36+
37+
```php
38+
'anycable' => [
39+
'driver' => 'anycable',
40+
],
41+
```
42+
43+
AnyCable supports Pusher protocol, so your client-side code stays the same. For example:
44+
45+
```js
46+
import Echo from "laravel-echo";
47+
48+
// We use Pusher protocol for now
49+
import Pusher from "pusher-js";
50+
window.Pusher = Pusher;
51+
52+
window.Echo = new Echo({
53+
broadcaster: "reverb", // reverb or pusher would work
54+
key: import.meta.env.VITE_REVERB_APP_KEY,
55+
wsHost: import.meta.env.VITE_REVERB_HOST,
56+
wsPort: import.meta.env.VITE_REVERB_PORT ?? 80,
57+
wssPort: import.meta.env.VITE_REVERB_PORT ?? 443,
58+
forceTLS: (import.meta.env.VITE_REVERB_SCHEME ?? "https") === "https",
59+
enabledTransports: ["ws", "wss"],
60+
});
61+
```
62+
63+
Just make sure you point to to the AnyCable server (locally it runs on the same host and port as Reverb).
64+
65+
Finally, install AnyCable server. We provide a convenient Artisan command that automatically downloads (when necessary) and runs the server:
66+
67+
```sh
68+
php artisan anycable:server -- --pusher_app_key=my-app-key
69+
```
70+
71+
The `--pusher_app_key` must be the same as the `VITE_REVERB_APP_KEY` for your client.
72+
To use public channel, you must also provide the `--public_streams` flag. You can also create an `anycable.toml` configuration file (see [docs](/anycable-go/configuration?id=configuration-files)).
73+
74+
Alternatively, you can install AnyCable using [other available options](/anycable-go/getting_started?id=installation).
75+
76+
That's it! Run your Laravel application, launch AnyCable server, and you should see your Echo client connecting to it and receiving updates.
77+
78+
## Limitations
79+
80+
- Presence channels are yet to be implemented.
81+
82+
- Only HTTP broadcasting adapter for AnyCable is supported for now.
83+
84+
[anycable-laravel]: https://github.com/anycable/anycable-laravel
85+
[laravel-anycable-demo]: https://github.com/anycable/laravel-anycable-demo

0 commit comments

Comments
 (0)