Let's start quickly. If you want to create a Progress Bar and see it in the Terminal, let us show you the steps so that it can be used in any project idea
First, we create a command
php artisan make:command ProgressBarTestCommand
Inside app/Console/Commands/ProgressBarTestCommand.php
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class ProgressBarTestCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'progressbar:test';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
$items = range(1, 3);
$progressbar = $this->output->createProgressBar(count($items));
$progressbar->start();
foreach ($items as $item) {
// perform some operation
sleep(1);
$progressbar->advance();
}
$progressbar->finish();
return 0;
}
}
Let's choose it and see the result and tell us about it in the comments
php artisan rogressbar:test
I hope you enjoyed the code.
Source :- https://laravel.com/docs/8.x/artisan#progress-bars
Source :- https://www.youtube.com/watch?v=H4mxFUlR1vc
Top comments (0)