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.