Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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