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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners