Could we help you? Please click the banners. We are young and desperately need the money
Laravel's Artisan CLI is great for building custom commands. But when your script runs longer than a few seconds, it’s useful to give the user some visual feedback. That’s where Laravel’s progress bars come in. You can show how far along your command is.
Laravel gives you possibility to display progress of your CLI command.
class ImportUsers extends Command
{
protected $signature = 'secrets:import-users
{file : A CSV with the list of users}';
protected $description = 'Import users from a CSV file.';
public function handle()
{
$lines = $this->parseCsvFile($this->argument('file'));
$progressBar = $this->output->createProgressBar($lines->count());
$progressBar->start();
$lines->each(function ($line) use ($progressBar) {
$this->convertLineToUser($line);
$progressBar->advance();
});
$progressBar->finish();
}
// class specific methods
}
Adding a progress bar to your Laravel command is a small touch that can make a big difference. It gives users better visibility into what’s happening and makes your CLI scripts feel more polished. It’s easy to implement and helps improve the experience for anyone running your command.