Wave provides a Wave class that allows you to listen to Eloquent model events and broadcast notifications using a fluent API. This respects Laravel's native conventions for Model Events Broadcasting and Broadcast Notifications.
Basic Usage
Initialize the Wave instance and use the .model() method to target a specific model by its name and primary key.
Customizing Namespaces
By default, Wave assumes models are in the App.Models namespace. You can override this during initialization using the namespace option.
import { Wave } from 'laravel-wave';
// Initialize with custom namespace if needed
window.Wave = new Wave({namespace: 'App.Path.Models'});
// Listen to events for a specific model instance
window.Wave.model('User', '1')
.notification('team.invite', (notification) => {
console.log(notification);
})
.updated((user) => console.log('user updated', user))
.deleted((user) => console.log('user deleted', user))
.trashed((user) => console.log('user trashed', user))
.restored((user) => console.log('user restored', user))
.updated('Team', (team) => console.log('team updated', team));