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

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
Agent Run Observability in Laravel AI SDK 0.11 image

Agent Run Observability in Laravel AI SDK 0.11

Read article
Debounced Queued Event Listeners in Laravel image

Debounced Queued Event Listeners in Laravel

Read article
Statamic Mailables Viewer Previews Laravel Emails in the Control Panel image

Statamic Mailables Viewer Previews Laravel Emails in the Control Panel

Read article
Laravel Tackle: Run an AI Coding Agent in Your Laravel App image

Laravel Tackle: Run an AI Coding Agent in Your Laravel App

Read article
Queue::forward(): Reroute Laravel Queues in One Place image

Queue::forward(): Reroute Laravel Queues in One Place

Read article
Laravel Read-Through Filesystem: Lazy Storage Migration image

Laravel Read-Through Filesystem: Lazy Storage Migration

Read article