Laravel 5 如何在Laravel chunk函数中添加progressbar

Laravel 5 如何在Laravel chunk函数中添加progressbar,laravel-5,Laravel 5,我想对customer表做些什么,因为有很多记录,所以我将使用chunk函数来处理每100条记录。我还想添加一个进度条来显示进度 但是我写的代码不起作用。 错误发生在“$bar”变量处 $count = DB::table('customers')->count(); $bar = $this->output->createProgressBar($count); DB::table('customers')->chunk(100, function ($custome

我想对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();
}

这是正确的方法:

->chunk(100, function ($users) use ($bar){}

这是正确的方法:

->chunk(100, function ($users) use ($bar){}

前面的答案是50%正确

DB::table('customers')->chunk每100行运行一次,因此必须添加$bar->finish();退出回调

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

DB::table('customers')->chunk(100, function ($customers,$bar) use($bar) {
  foreach($customers as $customer) {
   //do something with customer
   $bar->advance();
  }
}
$bar->finish();

前面的答案是50%正确

DB::table('customers')->chunk每100行运行一次,因此必须添加$bar->finish();退出回调

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

DB::table('customers')->chunk(100, function ($customers,$bar) use($bar) {
  foreach($customers as $customer) {
   //do something with customer
   $bar->advance();
  }
}
$bar->finish();