Closed FrancisMawn closed 2 years ago
Hi @FrancisMawn, try this.
$this->info('Info message');
@leandrodiogenes Not working:
Call to undefined method App\Actions\InstallApplication::info()
Im sorry, take some time check the docs in that session. https://laravelactions.com/2.x/as-command.html#methods-used
namespace App\Actions;
use Illuminate\Console\Command;
class TestCommandAction extends Action {
public string $commandSignature = 'test-action';
public function asCommand(Command $command): void {
$command->info('Done!');
}
}
Im sorry, take some time and read my original post :)
I know I can use the $command->info()
method. That's what I'm currently using. I was asking for a way to use the components instance on the Illuminate\Console\Command class.
public function asCommand(Command $command): void
{
$command->components->info('Done!');
}
sorry, but im a little confused to know what the difference between the two ways of using it.
I dont think we can access that property. As it is a protected property and there is a notice on it.
namespace Illuminate\Console\Concerns;
trait InteractsWithIO
{
/**
* The console components factory.
*
* @var \Illuminate\Console\View\Components\Factory
*
* @internal This property is not meant to be used or overwritten outside the framework.
*/
protected $components;
As you can see, the difference is the formatting. I wanted to see if there was a way to leverage the same output as the other commands.
When using a standard Command class, you can access the components
property.
Im gonna make a pull request to solve that problem, let's hope to be accepted.
Thanks for raising this and @leandrodiogenes for the PR!
I've merged and published this as part of v2.4.1
.
Hi,
I was trying to make use of the new components property on the Laravel Command class to enhance messages output to the console. So for example, with a regular command class, you can do stuff like
However, trying to access the components property on the injected Command instance throws the following exception:
Am I doing something wrong?