Laravel Console Task

Laravel Console Task

Laravel Console Task is a package by Nuno Maduro that allows you to perform tasks and to output the results to the console.

For example, let’s say your package comes with a console command that checks for certain requirements to validate that the installation is compatible with your PHP environment:

<?php

/**
 * Execute the console command.
 *
 * @return void
 */
public function handle()
{
    $this->info('Checking requirements...');

    $redisInstalled = $this->task('redis PECL module', function () {
        return extension_loaded('redis');
    });

    $bcmathInstalled = $this->task('bcmath module', function () {
        return extension_loaded('bcmath');
    });

    // ...
}

As seen in the above example, the macro returns the result of the closure, which means you can capture the result in a variable if you need to reference the outcome later in your console.

If you’re interested in the implementation behind this package, check out Nuno’s Laravel Console Task post on Medium. You can also check out the macro implementation here that makes $this->task() possible in Artisan console commands.

For complete installation instructions and the source code, check out the nunomaduro/laravel-console-task repo on GitHub.


Filed in: News / Artisan / console


Newsletter

Join the weekly newsletter and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Laravel + Vue.JS developer
Remote or in Toronto Canada
Star Dot Hosting Inc
Full Stack or Back-End Developer
Alexandria, VA; Tallahassee, FL; Orlando, FL
Marketing for Change
Senior Quality Assurance Engineer
Remote
Bisnow Media
Senior PHP/Laravel Developer: Your Dream Work Environment
Remote
iPhone Photography School
Senior Software Engineer
Remote or San Francisco
Curology
Laravel Developer
Las Vegas, NV
V Shred
R&D Developer
Denver, CO
booj