Laravel Tutorials

Generating Missing Events in Laravel

Published

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 L. Barnes photo

Eric is the creator of Laravel News and has been covering Laravel since 2012.

Sponsored

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article