nunomaduro/laravel-console-task
Laravel Console Task adds a simple $this->task() helper to Laravel Artisan commands to display task progress with a loading message and clear success/failure results. Works with Laravel 10+ and PHP 8.2+.
Install the package via Composer and start using the task() method inside any console command. The most common first use case is wrapping slow or multi-step operations (like database migrations, config publishing, or external API calls) to give users visual feedback with a clean progress indicator and success/failure status.
composer require nunomaduro/laravel-console-task
Then in a command (e.g., php artisan make:command DeployApp):
use Illuminate\Console\Command;
class DeployApp extends Command
{
protected $signature = 'app:deploy';
public function handle()
{
$this->task('Running migrations', function () {
return $this->call('migrate:fresh', ['--force' => true]);
});
$this->task('Seeding database', function () {
$this->call('db:seed');
return true;
});
return self::SUCCESS;
}
}
Start by reading the README and try wrapping a simple sleep(2) or dd() call to see the UI output locally.
task() for discrete, self-contained actions—ideally one operation per task. This makes failures easier to debug and re-run.true for success, false/null/non-true for failure. For Artisan command calls, return 0 (success) or non-zero (failure), but wrap with explicit return $result === 0; if needed to signal success.$this->task('Building assets', function () {
$this->call('vendor:publish', ['--provider' => 'AppServiceProvider']);
return true;
}, 'Publishing assets...');
task() calls—use separate top-level tasks instead for better readability and failure isolation.task() method outputs to OutputInterface, so use Laravel’s assertExitCode(0) and test output expectations via $this->artisan()->assertOutputContains('✔ Running migrations') when necessary.0 (from call()) works if cast to boolean, but 0 === false is falsy—use strict comparisons or cast: (bool) $this->call(...).--no-interaction), the package still works, but progress indicators may fall back to minimal output.Artisan::call() in subprocesses or use queue jobs instead.withProgressBar() or the Symphony ProgressBar directly—task() is for discrete high-level steps, not sub-step tracking.How can I help you explore Laravel packages today?