I want a custom piece of middleware to run whenever I run an artisan command. I need to set a few environment variables to be used in the app configuration before the actual command executes but Im not able to find any documentation on the Artisan request lifecycle.
Is this possible to do?
I found a way, not sure if the correct one, but works. Just open up the Kernel class and override the bootstrap method. Laravel 5.3, have not tested on other versions, but should work similiary.
class Kernel extends ConsoleKernel
{
protected $commands = [
// Your commands here
];
public function bootstrap()
{
// Don't forget to call parent bootstrap
parent::bootstrap();
// Do your own bootstrapping stuff here
}
protected function schedule(Schedule $schedule)
{
// Add cron schedules here, if needed
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With