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:
but I'm having problems including it in my seeder.
<?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(); } }
or
<?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(); } }
from https://mattstauffer.co/blog/advanced-input-output-with-artisan-commands-tables-and-progress-bars-in-laravel-5.1
Any ideas?
Laravel includes the ability to seed your database with data using seed classes. All seed classes are stored in the database/seeders directory. By default, a DatabaseSeeder class is defined for you. From this class, you may use the call method to run other seed classes, allowing you to control the seeding order.
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(); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With