Last active
September 5, 2024 02:14
-
-
Save djaiss/6685a6033b62e7eb3430b80a3bf258cc to your computer and use it in GitHub Desktop.
Laravel: Use progress bars in migrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Symfony\Component\Console\Helper\ProgressBar; | |
use Symfony\Component\Console\Output\ConsoleOutput; | |
class DoSomething extends Migration | |
{ | |
public function up() | |
{ | |
$output = new ConsoleOutput(); | |
$progress = new ProgressBar($output, count($contacts)); | |
$progress->start(); | |
foreach ($contacts as $contact) { | |
// DO SOMETHING | |
$progress->advance(); | |
} | |
$progress->finish(); | |
} | |
} |
Thanks. Very helpful 😃
Show!!!
Thanks!!!
Great! Really useful! Thank you!
I'd suggest to add this line after $progress->finish();
$output->write('', true);
If you wish to not overwrite the name of the migration currently being done, put a $output->writeln('');
between the ConsoleOutput instantiation and the ProgressBar object instantiation, i.e
$output = new ConsoleOutput();
$output->writeln('');
$progress = new ProgressBar($output, count($contacts));
Much appreciated!
That's insane thank you so much!
Thank you
Excellent snippet. Thank you!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this 👍