Skip to content

Instantly share code, notes, and snippets.

@sgpopov
Forked from jeffochoa/ProgressBarCallback.php
Created May 9, 2019 15:48
Show Gist options
  • Save sgpopov/144e54829808e80696f90f392d9d9f49 to your computer and use it in GitHub Desktop.
Save sgpopov/144e54829808e80696f90f392d9d9f49 to your computer and use it in GitHub Desktop.
ProgressBar callback trait for Laravel commands
<?php
$users = App\User::all();
$bar = $this->output->createProgressBar(count($users));
$bar->start();
foreach ($users as $user) {
$this->performTask($user);
$bar->advance();
}
$bar->finish();
<?php
namespace App\commands;
trait ProgressionBarOutput
{
public function runProcess(\Countable $countable, callable $callback)
{
$bar = $this->output->createProgressBar(count($countable));
$bar->start();
foreach ($countable as $item) {
call_user_func($callback, $item);
$bar->advance();
}
$bar->finish();
$this->line('');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment