Category: Laravel

For hotlaps.io I generate typed field accessors for every model field to get easier access to the data stored in a model. Looking through the Laravel documentation, there didn’t seem to be a way to register some code to run some other code after a command ran.

After digging a bit into how Artisan commands are run, I saw that after every command finishes to run, a CommandFinished event is dispatched by the framework — a perfect place for me to start!

Now that I knew what event to listen for I only had to add the event listener to my EventServiceProvider class and things should be good to go.

Every time I run php artisan migrate or php artisan migrate:rollback my event listener will also run my custom Artisan command to re-generate the field accessor traits for all my models.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners