use Symfony\Component\EventDispatcher\EventDispatcher; use App\Events\UserRegisteredEvent; $dispatcher = new EventDispatcher(); // Register event listener $dispatcher->addListener('user.registered', function (UserRegisteredEvent $event) { // send welcome email to user // add user details to database }); // Trigger event $dispatcher->dispatch('user.registered', new UserRegisteredEvent($userData));
use League\Event\Emitter; use App\Events\OrderPlacedEvent; $emitter = new Emitter(); // Register event listener $emitter->addListener('order.placed', function (OrderPlacedEvent $event) { // send email notification to customer // update order status // generate invoice }); // Trigger event $emitter->emit('order.placed', new OrderPlacedEvent($orderData));
use Evenement\EventEmitter; use App\Events\UserLoggedInEvent; $emitter = new EventEmitter(); // Register event listener $emitter->on('user.loggedin', function (UserLoggedInEvent $event) { // log user activity // update user's last login time // redirect user to dashboard }); // Trigger event $emitter->emit('user.loggedin', new UserLoggedInEvent($userData));Package/Library: Evenement