I'm working on a project running an old version of Laravel (5.6). There's a lot of custom artisan commands in this project. Some of those commands should create a summary on the end of the execution. My first idea was to create a parent class, and all the commands extend from this class, something like:
<?php
abstract class ParentCommand extends Command
{
abstract protected function doYourStuff();
abstract protected function prepareSummaryData();
final public function handle()
{
$this->doYourStuff();
$this->createSummary($this->prepareSummaryData());
}
final protected function createSummary($data)
{
// Summary stuff in here...
}
}
But the problem is that Laravel does DI in the handle method, so the handle method in child classes could have a different signature, which is not allowed.. :(
Any idea of how to run something after the handle() method is executed?
What about using a trait ?