php – 在Laravel中播种数据库时使用进度条

php – 在Laravel中播种数据库时使用进度条,第1张

概述我必须将大量数据植入数据库中,并希望能够在发生这种情况时向用户显示进度条.我知道这是记录在案的: > https://laravel.com/docs/master/artisan#registering-commands(刚刚上方) > http://symfony.com/doc/2.7/components/console/helpers/progressbar.html 但我在播种机中遇到 我必须将大量数据植入数据库中,并希望能够在发生这种情况时向用户显示进度条.我知道这是记录在案的:

> https://laravel.com/docs/master/artisan#registering-commands(刚刚上方)
> http://symfony.com/doc/2.7/components/console/helpers/progressbar.html

但我在播种机中遇到问题.

<?PHPuse 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();    }}

要么

<?PHPuse 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();    }}

从https://mattstauffer.co/blog/advanced-input-output-with-artisan-commands-tables-and-progress-bars-in-laravel-5.1

有任何想法吗?

您可以通过$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();}
总结

以上是内存溢出为你收集整理的php – 在Laravel中播种数据库时使用进度条全部内容,希望文章能够帮你解决php – 在Laravel中播种数据库时使用进度条所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1265422.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存