-
$bar = $this->output->createProgressBar($count); Their is an error running this on external class.. // this is like a sample commnad in commands
...
handle() {
$this->info('Setting Up Transfer...');
$stripeSubscriptionTransfer = new TransferActiveStripeSubscriptionToEmr(); // this has the $this->output->createProgressBar($count); in it
$this->info('Executing Transfer Function..');
$stripeSubscriptionTransfer->transfer();
}
... |
Beta Was this translation helpful? Give feedback.
Answered by
JenuelDev
Sep 6, 2022
Replies: 3 comments 1 reply
-
It might help if you could post the exception traceback. |
Beta Was this translation helpful? Give feedback.
1 reply
-
So for those who having with this one this is how I solved it. So I created a command with a handle with something like this. // this is sample handle from the command which can
// be found in app\Console\Commands after creating command `php artisan make:command <name>`
...
public function handle() {
(new ExampleClassHere())->sampleFunctionHere();
}
... and in that class // we need to extend our commands this way we
// can use $this->info,$this->line() etc. to write console output
use Illuminate\Console\Command;
use Symfony\Component\Console\Helper\ProgressBar;
class ExampleClassHere extends Command {
public function __construct()
{
parent::__construct();
// I dont know but it seems like we need to set this on the
// construct for the console ouput functions to work properly.
$this->output = new \Symfony\Component\Console\Output\ConsoleOutput();
}
// so this is how I solved the progress bar error
public function sampleFunctionHere() {
/**
$bar = $this->output->createProgressBar($count); -> this is having problems to me,
it throws an error that the createProgressBar function is undefined. So I have no choice,
so I have to grab some class on the Symfony, which is ProgressBar and imported it. Now I can use it like this.
See code sample bellow.
*/
$datas = [1,2,3,4,5,6,7,8,9,0]
$count = count($data);
$bar = new ProgressBar($this->output,$count);
$bar->start(); // to start the progress bar
foreach($datas as $data) {
// your methods here or any thing you can add here
$bar->advance(); // to add progress to progress bar
}
$bar->finish(); // to finish the progress bar
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
JenuelDev
-
Or you use my package henzeb/laravel-console-facade. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So for those who having with this one this is how I solved it.
So I created a command with a handle with something like this.
and in that class