I would like to display processing progress using a simple series of dots. This is easy in the browser, just do echo '.'
and it goes on the same line, but how do I do this on the same line when sending data to the artisan commandline?
Each subsequent call to $this->info('.')
puts the dot on a new line.
There is very easy way to create a view(blade) file with php artisan make:view {view-name} command using Laravel More Command Package.
Artisan is the name of the command-line interface included with Laravel. It provides a number of helpful commands for your use while developing your application. It is driven by the powerful Symfony Console component.
To call another Artisan command and save its output you should use $this->call() from your command.
The method info uses writeln, it adds a newline at the end, you need to use write instead.
//in your command
$this->output->write('my inline message', false);
$this->output->write('my inline message continues', false);
Probably a little bit of topic, since you want a series of dots only. But you can easily present a progress bar in artisan commands using built in functionality in Laravel.
Declare a class variable like this:
protected $progressbar;
And initialize the progress bar like this, lets say in fire() method:
$this->progressbar = $this->getHelperSet()->get('progress');
$this->progressbar->start($this->output, Model::count());
And then do something like this:
foreach (Model::all() as $instance)
{
$this->progressbar->advance(); //do stuff before or after this
}
And finilize the progress when done by calling this:
$this->progressbar->finish();
Update: For Laravel 5.1+ The simpler syntax is even more convenient:
$bar = $this->output->createProgressBar(count($foo));
$bar->advance();
$bar->finish();
If you look at the source, you will see that $this->info
is actually just a shortcut for $this->output->writeln
: Source.
You could use $this->output->write('<info>.</info>')
to make it inline.
If you find yourself using this often you can make your own helper method like:
public function inlineInfo($string)
{
$this->output->write("<info>$string</info>");
}
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