Skip to content

Instantly share code, notes, and snippets.

@jeffochoa
Last active May 28, 2019 16:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jeffochoa/1113e86a6ceaf61c914f2a4f0def630e to your computer and use it in GitHub Desktop.
Save jeffochoa/1113e86a6ceaf61c914f2a4f0def630e 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