Even with the detailed answers above, I still had problems understanding what the real difference is between using a controller / function OR an event listener.
One of the things that was missing in all of these answers is that using events and event listeners is useful when you don't want to put together your code so closely . Each function, class, etc. Must have a single goal.
Suppose you received an API request from an outsider. In my case, my exact problem with understanding this concept was when I get API calls from Stripe Webhooks.
The goal of Stripe Webhooks: let's say a client spends $ 10,000 on your website. Your standard procedure is Authentication and Capture. Update your database to reflect their new membership status. In an ideal world, and in the case of our company, 999/1000 times, it goes perfectly. Either their card will be declined on the spot, or the payment will go through. In both cases, we send them a notification email.
But what about the time 1/1000 when the user pays, and Stripe returns a "Card Error" error (this can be many different things)? In our case, we send them an e-mail and inform them that billing has failed. The problem we are facing is that some BANKS investigate large payments that are returned as an Error, but then, after a few minutes, the bank authorizes the payments and the payment is fixed.
So what is there to do? Enter the strip of Webhooks. Stripe Webhooks will go to the API endpoint if something like this happens. In fact, Stripe Webhooks can use your API every time a payment is not processed instantly, verified, received, or if a customer requests a refund.
This is where the event receiver comes in handy. The bar fires through POST with client information, as well as the Webhook type. Now we will process this, update the database and send them a successful email.
But why not just use the standard route and controller? The reason why we do not just use the standard route and controller is because we need to either change already defined functions, classes, etc., Or create a new series of classes that are connected together, for example → Stripe API Calls Received Database update, Email sending. Instead of binding them together, we use an event receiver to first accept an API call, and then click on each of these classes, functions, etc., leaving everything unconnected.
I searched everywhere and I think the Laravel documentation explains this best. When I gave a concrete example, I finally realized what the purpose of the event listener is:
Events are a great way to separate the various aspects of your application, as a single event can have multiple listeners that are independent of each other. For example, you can send Slack notifications to your user every time an order is sent. Instead of associating an order processing code with a Slack notification code, you can trigger an OrderShipped event, which the listener can receive and convert to a Slack notification.
https://laravel.com/docs/5.6/events