为什么使用事件监听器而不是库类或根本不使用它

Why would you write code into Laravel Event Listeners such as Event::listen('user.login', 'LoginHandler') instead of directly into the controller function?

And if several different controller functions call the same code, why would you use Event listeners rather than calling a static function from a library class?

One possible instance would be when writing "Plugins" for your site that can be enabled/disabled at will and hook into certain events in the core code.

If you just want to write something for personal use with full control over the code, you should just use library classes.

For example I create a package that want to send an API call each time a user logged in, with Event listener I can just simply add the event without touching the library.

Now what if I instead change the library class? What would happen if there another package that want to replace the same library class? It will become tedious (or rather limiting) where you have to pick one option over the other.