ProgressBar callback trait for Laravel commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$users = App\User::all(); | |
$bar = $this->output->createProgressBar(count($users)); | |
$bar->start(); | |
foreach ($users as $user) { | |
$this->performTask($user); | |
$bar->advance(); | |
} | |
$bar->finish(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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