Jeff Ochoa

ProgressBar callback trait for Laravel commands

ProgressBar callback trait for Laravel commands - JeffOchoa.me

A progress bar is an excellent way to have some feedback when you are writing and running long process using Laravel commands.

TL;DR Using the output object, we can start, advance and stop the Progress Bar.

According to the Laravel official documentation, this is only what you need to create a progress bar:

Pretty straight forward, although you can use a different approach to avoid repeating the same code over and over.

Creating ProgressBarCallback trait

The following trait has a method that receives two arguments, a countable object and a callback and what it does is to create the progress bar, then run the given callback for each one of the items in the countable variable.

Here you can see a dummy example.

https://twitter.com/Jeffer_8a/status/1121164390655512577

You can learn more about the Laravel Artisan Console by reading the official documentation

https://laravel.com/docs/5.8/artisan

That's all!

I hope you like it.

Do you have any tips and tricks to share? Please reach out on Twitter.

Cheers ?

Share This Article

Continue reading