0

I am trying to create a progress bar in an artisan command. The version of laravel i am using is 5.0 (although it has been updated from 4.x so the commands are stored in the folder app/Console/Commands and are in the namespace Foundry\PhoneHome\Console\Commands)

I am running $this->output->progressStart($count); and have also tried $this->output->createProgressBar($count); but for both of them i get the error [Symfony\Component\Debug\Exception\FatalErrorException] Call to undefined method Symfony\Component\Console\Output\ConsoleOutput::progressStart()

Am i doing something wrong or are the progress bars not supported in laravel 5.0?

SamBremner
  • 793
  • 2
  • 10
  • 22

1 Answers1

1

Progress bars were entered in Laravel 5.1, you can upgrade your Laravel (recommended) or writing a simple progress bar by yourself.

Inside your command, add the following function:

private function updateProgress($done, $total) {
    $perc = floor(($done / $total) * 50);
    $left = 50 - $perc;
    $write = sprintf("\033[0G\033[2K[%'={$perc}s>%-{$left}s] - $perc%% - $done/$total", "", "");
    fwrite(STDERR, $write);
}

public function handle() {
     // your logic
     $this->updateProgress(1,10);
}

You can see more implementations here Command line progress bar in PHP

inet123
  • 764
  • 6
  • 10