Skip to content

Instantly share code, notes, and snippets.

@djaiss
Last active September 5, 2024 02:14
Show Gist options
  • Save djaiss/6685a6033b62e7eb3430b80a3bf258cc to your computer and use it in GitHub Desktop.
Save djaiss/6685a6033b62e7eb3430b80a3bf258cc to your computer and use it in GitHub Desktop.
Laravel: Use progress bars in migrations
<?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();
}
}
@hubsta
Copy link

hubsta commented Jul 12, 2018

Thanks for this 👍

@mateussantana
Copy link

Thanks. Very helpful 😃

@JorgeBeserra
Copy link

Show!!!

Thanks!!!

@ologo
Copy link

ologo commented Jun 17, 2021

Great! Really useful! Thank you!

I'd suggest to add this line after $progress->finish();

$output->write('', true);

@JordanPlayz158
Copy link

JordanPlayz158 commented Oct 2, 2022

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));

@mrl22
Copy link

mrl22 commented Jul 18, 2023

Much appreciated!

@guymarshallpnp
Copy link

That's insane thank you so much!

@jonhassall
Copy link

Thank you

@pointybeard
Copy link

Excellent snippet. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment