I have to seed quite a lot of data into a database and I want to be able to show the user a progress bar while this happens. I know this is documented:
- https://laravel.com/docs/master/artisan#registering-commands (just above)
- http://symfony.com/doc/2.7/components/console/helpers/progressbar.html
but I’m having problems including it in my seeder.
<?php use IlluminateDatabaseSeeder; 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(); } }
or
<?php use IlluminateDatabaseSeeder; 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(); } }
Any ideas?
Advertisement
Answer
You can get access to output through $this->command->getOutput()
public function run() { $this->command->getOutput()->progressStart(10); for ($i = 0; $i < 10; $i++) { sleep(1); $this->command->getOutput()->progressAdvance(); } $this->command->getOutput()->progressFinish(); }