Calling info() outside of command
Is it possible to call info() outside the command? Or do I have to pass the command's $this to the other class so I can call info() through it?
I'm not entirely sure what you mean, do you mean in another class that is called by the command?
The info() method is provided by the underlying Laravel Command class.
https://github.com/illuminate/console/blob/master/Concerns/InteractsWithIO.php#L273-L283
Not sure whether this will help, but what I do is pass the instance of the command ($this) to the class I am invoking within the command.
Is it possible to call
info()outside the command? Or do I have to pass the command's$thisto the other class so I can callinfo()through it?
You can useIlluminate\Console\Concerns\InteractsWithIO trait in any class to access those output methods.
Also, you need to set the output property.
An example,
namespace App\Services;
use Illuminate\Console\Concerns\InteractsWithIO;
use Symfony\Component\Console\Output\ConsoleOutput;
class SomeService
{
use InteractsWithIO;
public function __construct()
{
$this->output = new ConsoleOutput();
}
public function doSomething(string $text)
{
$this->line($text);
}
}
Going to close this as it's a really old issue, and has solutions here. 🤷🏻