If you only need to execute some method when each command were executed, you can listen this class.
Illuminate\Console\Events\ArtisanStarting
But i don't know how to get name of every command inside listener.
I want to run a method when every single console command is run, How do I create a listener for all console commands in lumen?
I tried by creating a listener for ConsoleCommandEvent
, this event is fired in \Symfony\Component\Console\Application::doRunCommand
, but event dispatcher has not been attached (read the comment above the method: If an event dispatcher has been attached to the application, events are also dispatched during the life-cycle of the command.)
Update Using this event: Illuminate\Console\Events\ArtisanStarting
might help to do the job, but it is a different event. By doing so any time that you run php artisan
your code will be executed whether you run an actual command or not.
0 Comments