Generating Missing Events in Laravel
Published on by Eric L. Barnes
Via Matt Stauffer:
Sometimes it’s a lot of work to create an event, create its handler, and bind the two. Create a command, create its handler, bind the two. I’ve often wished for a workflow that handled the whole process together in one.
The artisan commands for generating commands and events are a good start–they both create their own entity and (optionally) its handler. But you still can spend an hour writing the command and handler, and then waste another 15 minutes trying to figure out why it’s not working, only to realize you never actually bound the two together.
Well, dear reader, your white-knuckled wait is finally over. In Laravel 5, you can bind (non-existen) events and handlers in the EventServiceProvider, run php artisan event:generate, and Artisan will automatically generate the files for you–both for the Event and its Handler.
Matt’s been a role lately with all the new Laravel goodies. It’s neat to get see all these useful features explained before the docs are even created.
Eric is the creator of Laravel News and has been covering Laravel since 2012.