// subscribe to user registration event Event::subscribe('user.registered', function($userData) { // send email to user $email = new Email(); $email->send('welcome', $userData['email']); });
// subscribe to new message event Event::subscribe('new.message', function($message) { // broadcast message to all connected users foreach (Chat::getConnectedUsers() as $user) { $user->sendMessage($message); } });These examples use the Laravel framework's Event class, which is part of the package library of Laravel. The Event class provides a simple and convenient way to subscribe to and trigger events within a Laravel application.