Blog Detail


Write Shell Scripts like Blade Components in Laravel cover image

Write Shell Scripts like Blade Components in Laravel

Laravel Task Runner is a package to write Shell scripts like Blade Components and run them locally or on a remote server. Support for running tasks in the background and test assertions. Built upon the Process feature in Laravel 10.


This package requires Laravel 10 and PHP 8.1 or higher. You can install the package via Composer:

composer require protonemedia/laravel-task-runner

Optionally, you can publish the config file with:

php artisan vendor:publish --provider="ProtoneMedia\LaravelTaskRunner\ServiceProvider"

Basic usage

You may use the Artisan make:task command to create a Task class:

php artisan make:task ComposerGlobalUpdate

This will generate two files: app/Tasks/ComposerGlobalUpdate.php and resources/views/tasks/composer-global-update.blade.php.

Once you've added your script to the Blade template, you may run it on your local machine by calling the dispatch() method:


Alternatively, if you don't want a separate Blade template, you may use the --class option (or -c):

php artisan make:task ComposerGlobalUpdate -c

This allows you to specify the script inline:

class ComposerGlobalUpdate extends Task
    public function render(): string
        return 'composer global update';

Task output

The dispatch() method returns an instance of ProcessOutput, which can return the output and exit code:

$output = ComposerGlobalUpdate::dispatch();


$output->getLines();    // returns the buffer as an array
$output->isSuccessful();    // returns true when the exit code is 0
$output->isTimeout();    // returns true on a timeout

To interact with the underlying ProcessResult, you may call the getIlluminateResult() method:


Script variables

Just like Blade Components, the public properties and methods of the Task class are available in the template:

class GetFile extends Task
    public function __construct(public string $path)

    public function options()
        return '-n';

Blade template:

cat {{ $options() }} {{ $path }}

You can create a new instance of the Task using the static make() method:


Task options

You may specify a timeout. By default, the timeout is based on the task-runner.default_timeout config value.

class ComposerGlobalUpdate extends Task
    protected int $timeout = 60;


If you are a business and want to leverage Laravel for your next PHP-based web application, CRM Software, E-commerce application, SAAS application, or any custom web application development for your custom requirements, you must discover an amazing team with experience in the Laravel framework. So Codebrisk is here to help you with your tailored requirements regarding Laravel Development. Please feel free to send us an email at or get in touch with us, our business person will get back to you.

Published at : 30-05-2023

Author : Rizwan Aslam
Rizwan Aslam

I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.

Launch project