In this quick episode, we look at an easy way to speed up your Laravel workflow when you're dealing with events and listeners. Normally, you'd use Artisan commands to manually create your events and listeners, and then wire them up in your EventServiceProvider. That works, but it can get a bit repetitive and tedious, especially if your app is growing.
Instead, this video shows a handy trick: you can define your events and listeners as strings in your EventServiceProvider—even before creating their actual files. Then, by running php artisan event:generate
, Laravel will automatically create the event and listener classes for you if they don't already exist!
This means you can quickly scaffold out all the events and listeners you need just by specifying their names. And don't worry, if you've already created some of them, running the command again won't overwrite anything. It's a neat way to save time and keep your workflow smooth when setting up events in Laravel.