Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Console Task Laravel Package

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+.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Atomic Operations: Use task() for discrete, self-contained actions—ideally one operation per task. This makes failures easier to debug and re-run.
  • Return Value Semantics: Return 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.
  • Custom Loading Messages: Pass a third argument for clarity during long-running or ambiguous tasks:
    $this->task('Building assets', function () {
        $this->call('vendor:publish', ['--provider' => 'AppServiceProvider']);
        return true;
    }, 'Publishing assets...');
    
  • Nested Tasks: Avoid nesting task() calls—use separate top-level tasks instead for better readability and failure isolation.
  • Testing: The task() method outputs to OutputInterface, so use Laravel’s assertExitCode(0) and test output expectations via $this->artisan()->assertOutputContains('✔ Running migrations') when necessary.

Gotchas and Tips

  • Return Types Matter: The closure must return a truthy/falsy value. Returning 0 (from call()) works if cast to boolean, but 0 === false is falsy—use strict comparisons or cast: (bool) $this->call(...).
  • Non-Interactive Mode: In CI or headless environments (e.g., --no-interaction), the package still works, but progress indicators may fall back to minimal output.
  • Exception Handling: If the closure throws an exception, the task is marked as failed with a stack trace—wrap risky code in try/catch if you want graceful degradation or partial recovery.
  • No Built-in Parallelism: Tasks are sequential. For parallelism, orchestrate via Laravel’s Artisan::call() in subprocesses or use queue jobs instead.
  • Output Formatting: The package uses UTF-8 checkmarks (✔/✖) and subtle animation—ensure your terminal supports these (大多数 modern terminals do; older Windows consoles may show symbols instead).
  • Extension Tip: If you need persistent progress bars (e.g., for huge loops), consider combining with Laravel’s built-in withProgressBar() or the Symphony ProgressBar directly—task() is for discrete high-level steps, not sub-step tracking.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport