#1 India's Top IT Training Institute

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Working with Events and Listeners

Events let different parts of a Laravel application react to something happening without tightly coupling the code that triggers it to the code that responds to it.

Why Decouple With Events

Without events, a controller might directly call code to send an email, log an entry, and update a cache all in one place. With events, the controller simply announces "this happened" and any number of listeners can react independently.

The Pieces Involved

PieceRole
EventA simple class describing what happened
ListenerA class that reacts to the event
EventServiceProviderMaps events to their listeners

Registering the Mapping

protected $listen = [
    OrderShipped::class => [
        SendShipmentNotification::class,
    ],
];

Laravel can also auto-discover listeners without manual registration if event discovery is enabled.

Understanding this relationship sets up the next, more hands-on step: actually writing and firing a custom event.

Ready to master Laravel Training Course?

Join Uncodemy's hands-on Laravel program and build real, production-ready applications.

Explore Course