Skip to main content
Lyger provides a powerful event system for decoupling application logic and enabling real-time features. Events can be dispatched, listened to, and broadcast across channels.

Creating Events

Events extend the base Event 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:
Wildcard listeners run for every matching event. Use them sparingly to avoid performance issues.

Event Service Provider

Organize event listeners in a service provider:

Broadcasting Events

Broadcast events to WebSocket channels for real-time updates:

Broadcastable Events

Implement the ShouldBroadcast 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

For expensive operations, dispatch jobs instead of blocking:
Batch similar events to reduce overhead:

Next Steps

WebSockets

Real-time communication

Jobs & Queues

Background processing