Creating Events
Events extend the baseEvent class and contain data about what happened:
Events automatically get their name from the class name.
UserRegistered becomes “UserRegistered” in the event system.Dispatching Events
Trigger events when important actions occur:Event Listeners
Register listeners to respond to events:Basic Listener
Multiple Listeners
Multiple listeners can respond to the same event:Wildcard Listeners
Listen to multiple events with pattern matching:Event Service Provider
Organize event listeners in a service provider:Broadcasting Events
Broadcast events to WebSocket channels for real-time updates:Broadcastable Events
Implement theShouldBroadcast interface:
Broadcasting Manually
Channel Types
Lyger supports different channel types for broadcasting:Public Channel
Private Channel
Presence Channel
Real-World Examples
User Activity Tracking
Order Processing Pipeline
Real-Time Notifications
Event Utilities
Check for Listeners
Clear Listeners
Testing Events
Mock events in tests:Performance Tips
Async Listeners
Async Listeners
For expensive operations, dispatch jobs instead of blocking:
Event Batching
Event Batching
Batch similar events to reduce overhead:
Next Steps
WebSockets
Real-time communication
Jobs & Queues
Background processing