Php Laravel进度条被覆盖
我有一个命令,其中我做3个循环,我想为每个循环显示3个进度条。 在我的输出中,进度条被覆盖,我只能看到1 我的代码:Php Laravel进度条被覆盖,php,laravel,Php,Laravel,我有一个命令,其中我做3个循环,我想为每个循环显示3个进度条。 在我的输出中,进度条被覆盖,我只能看到1 我的代码: public function handle() { $this->setUsers('a', UserModel::all()->where('type', 'a')); $this->setUsers('b', UserModel::all()->where('type', 'b')); $this->setUsers('
public function handle()
{
$this->setUsers('a', UserModel::all()->where('type', 'a'));
$this->setUsers('b', UserModel::all()->where('type', 'b'));
$this->setUsers('c', UserModel::all()->where('type', 'c'));
}
private function setUsers(string $type, $users)
{
$bar = $this->output->createProgressBar(count($users));
$bar->start();
/** @var UserModel $user */
foreach ($users as $user) {
$user->update(['type' => [$type]]);
$bar->advance();
}
$bar->finish();
}
这里的目标是查看已完成的3个进度条。当我在输出中添加新行时,它对我有效:
private function setUsers(string $type, $users)
{
$bar = $this->output->createProgressBar(count($users));
$bar->start();
/** @var UserModel $user */
foreach ($users as $user) {
$user->update(['type' => [$type]]);
$bar->advance();
}
print "\n";
$bar->finish();
}
您还可以找到很好的示例,例如同时显示所有进度条。当我在输出中添加新行时,它对我很有用:
private function setUsers(string $type, $users)
{
$bar = $this->output->createProgressBar(count($users));
$bar->start();
/** @var UserModel $user */
foreach ($users as $user) {
$user->update(['type' => [$type]]);
$bar->advance();
}
print "\n";
$bar->finish();
}
您还可以找到好的示例,例如同时显示所有进度条。您需要创建一个单独的部分,如
使用Symfony\Component\Console\Helper\ProgressBar;
...
私人产出;
公共函数运行(InputInterface$input,OutputInterface$output)
{
$this->symOutput=$output;
返回父级::运行($input,$output);
}
公共函数句柄()
{
$this->setUsers('a',UserModel::all()->其中('type','a');
$this->setUsers('b',UserModel::all()->其中('type','b');
$this->setUsers('c',UserModel::all()->其中('type','c');
}
私有函数setUsers(字符串$type,$users)
{
$section=$this->symOutput->section();
$bar=新进度条($section,count($users));
$bar->start();
/**@var UserModel$user*/
foreach($users作为$user){
$user->update(['type'=>[$type]]);
$bar->advance();
}
$bar->finish();
}
您需要创建一个单独的部分,如
使用Symfony\Component\Console\Helper\ProgressBar;
...
私人产出;
公共函数运行(InputInterface$input,OutputInterface$output)
{
$this->symOutput=$output;
返回父级::运行($input,$output);
}
公共函数句柄()
{
$this->setUsers('a',UserModel::all()->其中('type','a');
$this->setUsers('b',UserModel::all()->其中('type','b');
$this->setUsers('c',UserModel::all()->其中('type','c');
}
私有函数setUsers(字符串$type,$users)
{
$section=$this->symOutput->section();
$bar=新进度条($section,count($users));
$bar->start();
/**@var UserModel$user*/
foreach($users作为$user){
$user->update(['type'=>[$type]]);
$bar->advance();
}
$bar->finish();
}