Prerequisites
Before you begin, ensure you have:- Laravel 10+ application
- PHP 8.1+
- Laravel Reverb (for WebSocket connections)
- Node.js 18+ (for frontend integration)
Quick Start
The easiest way to get started is by using the React Starter Kit for Chorus. This starter kit is based on Laravel’s React Starter Kit, but with Chorus pre-installed and a simple example included, so you can hit the ground running. To get started, run this command in your favorite terminal:How to install into an existing Laravel App
Step 1: Install the Package
Install Laravel Chorus via Composer:Step 2: Run the Installer
The installer sets up everything you need:- Publish configuration files
- Create the harmonics database migration
- Set up Laravel Reverb (if not already installed)
- Generate TypeScript utilities in
resources/js/chorus - Configure broadcasting settings
- Install the appropriate Chorus package for your chosen framework
Step 3: Run Migrations
Create the harmonics table:Configuration
Database Configuration
Theconfig/chorus.php file contains all Chorus settings:
Your First Synchronized Model
Step 1: Add the Harmonics Trait
Add theHarmonics trait to any model you want to synchronize:
Step 2: Create Write Actions
Generate write actions for your model:app/Actions/WriteActions/:
Step 3: Update Model Configuration
Add your model to theconfig/chorus.php:
Frontend Integration
Step 1: Add the Chorus Provider
Wrap your app with the Chorus provider:Step 2: Use Data in Components
Use Chorus hooks to access synchronized data:Start the Servers
Start Reverb
Start the Laravel Reverb WebSocket server:Start Your Frontend
Testing Your Integration
- Open multiple browser tabs to your application
- Create, update, or delete messages in one tab
- Watch changes appear instantly in other tabs
- Go offline and make changes - they’ll sync when back online
Next Steps
Harmonics Trait
Add the Harmonics trait to your models
React Integration
Build real-time React components
Write Actions
Master server-side write operations and validation
Advanced Features
Set up multi-tenancy and advanced features
Troubleshooting
WebSocket Connection Issues
WebSocket Connection Issues
Ensure Reverb is properly configured and running. Check the browser console for connection errors. You can also run
reverb with the
--debug flag to see when harmonic events get fired.Changes Not Syncing
Changes Not Syncing
Verify the model has the Harmonics trait. Check server logs for errors.
Offline Writes Failing
Offline Writes Failing
Ensure write actions have
allowOfflineWrites => true and proper validation rules.Type Errors in Frontend
Type Errors in Frontend
Run
php artisan chorus:generate --types to regenerate TypeScript definitions.Congratulations! You now have Laravel Chorus running in your application. Your users will experience instant, real-time updates with full offline support.