Laravel Event/Listeners

You can use laravel events when you need to implement Observer Concept

Let’s Talking about Observer Design pattern and How work

Subject: is Event when Fired

Observer: is responsible about sending notifications to subscribers

Subscribers: are Listeners which wait for notification form observer and Handle Event action

Events should be registered via the EventServiceProvider and generated using $php artisan event:generate

Quick Example From laravel Doc from Four steps

[1] Register Event

[2] Event Logic

[3] Listener Logic

[4] Fire Event

[1] Here all events/Listeners is registers
[2] In OrderShipped event when is created should have variable type of Order
[3] this listener will handle OrderShipped event when Event Fired
[4] In ship method OrderShipped Event is Fired and passed order variable as OrderShipped constructor

thanks for reading By Refaat Aish