如何在Laravel块功能中添加进度条

问题描述 投票:1回答:1

我想用customer表做一些事情并且有很多记录所以我将使用chunk函数来完成每100条记录。我还想添加一个进度条来显示进度。

但我写的代码不起作用。错误发生在“$ bar”变量。

$count = DB::table('customers')->count();
$bar = $this->output->createProgressBar($count);

DB::table('customers')->chunk(100, function ($customers,$bar) {
  foreach($customers as $customer) {
   //do something with customer
   $bar->advance();
  }
  $bar->finish();
}
laravel-5
1个回答
1
投票

这是正确的方法:

->chunk(100, function ($users) use ($bar){}
© www.soinside.com 2019 - 2024. All rights reserved.