我必须将大量数据植入数据库中,并希望能够在发生这种情况时向用户显示进度条.我知道这是记录在案的:
> https://laravel.com/docs/master/artisan#registering-commands(刚刚上方)
> http://symfony.com/doc/2.7/components/console/helpers/progressbar.html
但我在播种机中遇到问题.
<?PHP use Illuminate\Database\Seeder; class SubDivisionRangeSeeder extends Seeder { public function run() { $this->output->createProgressBar(10); for ($i = 0; $i < 10; $i++) { sleep(1); $this->output->advance(); } $this->output->finish(); } }
要么
<?PHP use Illuminate\Database\Seeder; class SubDivisionRangeSeeder extends Seeder { public function run() { $this->output->progressStart(10); for ($i = 0; $i < 10; $i++) { sleep(1); $this->output->progressAdvance(); } $this->output->progressFinish(); } }
有任何想法吗?
您可以通过$this-> command-> getOutput()访问输出
原文链接:https://www.f2er.com/laravel/138617.htmlpublic function run() { $this->command->getOutput()->progressStart(10); for ($i = 0; $i < 10; $i++) { sleep(1); $this->command->getOutput()->progressAdvance(); } $this->command->getOutput()->progressFinish(); }