Here are the key steps to manage multiple Reverb applications in a single Laravel project:
Define Additional Applications
In the `config/reverb.php` configuration file, you can define multiple applications under the `apps` key. For example:
php
'apps' => [
[
'id' => 'app-one',
'allowed_origins' => ['app-one.com'],
// other app-specific configuration
],
[
'id' => 'app-two',
'allowed_origins' => ['app-two.com'],
// other app-specific configuration
],
]
This allows you to serve WebSocket connectivity for multiple applications using a single Reverb installation[1].
Set the Current Application
When broadcasting events or subscribing to channels, you need to specify which application the operation is for. You can do this by setting the `reverb.app` context:
php
use Laravel\Reverb\Facades\Reverb;
Reverb::setAppId('app-one');
// broadcast an event to app-one
event(new MyEvent());
Use the Reverb Facade
The `Reverb` facade provides methods to interact with the current application:
- `Reverb::channel()`: Define a channel for the current app[1]
- `Reverb::event()`: Broadcast an event to the current app
- `Reverb::auth()`: Authenticate a user for the current app's private channels
Configure Separate Environments
You can configure each application to use different environment variables for things like the WebSocket host, port, and scheme. This allows you to have separate configurations for development, staging, and production environments.
By following these steps, you can manage multiple Reverb applications within a single Laravel project, each with its own configuration and authentication. This enables you to serve WebSocket connectivity to multiple applications from a centralized Reverb server.
Citations:[1] https://laravel.com/docs/11.x/reverb
[2] https://tapansharma.dev/blog/how-to-install-and-configure-laravel-reverb-on-a-laravel-project
[3] https://www.youtube.com/watch?v=GscAFW6eoBQ
[4] https://www.itpathsolutions.com/mastering-laravel-reverb-shaping-the-future-of-real-time-web-applications/
[5] https://www.youtube.com/watch?v=gv9z1yv0_7k