Laravel Packages

Write Shell Scripts like Blade Components With Task Runner

Published
Write Shell Scripts like Blade Components With Task Runner image

Task Runner for Laravel is a package by Pascal Baljet that lets you write Shell scripts like Blade Components and run them locally or on a remote server:

{{-- resources/views/tasks/deploy-app.blade.php --}}
cd /var/www/html
git pull origin {{ $branch }}
php artisan migrate --database={{ $databaseConnection() }}

Given the conventions in this package, the above template would have an accompanying Task class:

use ProtoneMedia\LaravelTaskRunner\Task;
 
class DeployApp extends Task
{
public function __construct(public string $branch) { }
 
public function databaseConnection()
{
return 'mysql';
}
}

You might have noticed that the databaseConnection() public method is available as callable in the template. All public methods are available in task blade templates.

If you want to trigger the above task, you can use the package's dispatch() method, which will run it locally. You can also dispatch tasks in the background and also run them on a remote server:

$output = DeployApp::dispatch();
 
$output = DeployApp::inBackgronud()
->onConnection('web')
->dispatch();
 
// API of the task result
$output->getBuffer();
$output->getExitCode();
$output->isSuccessful();
$output->isTimeout();
// returns the buffer as an array
$output->getLines();

This package also has excellent testing helpers, which you can read about in the Documentation. You can learn more about this package, get full installation instructions, and view the source code on GitHub.

Paul Redmond photo

Staff writer at Laravel News. Full stack web developer and author.

Sponsored

laravelcloud logo
Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Visit Laravel Cloud

The latest

View all →
CPX: The Composer Package Executor for PHP image

CPX: The Composer Package Executor for PHP

Read article
Laravel AI SDK Adds Human-in-the-Loop Tool Approval image

Laravel AI SDK Adds Human-in-the-Loop Tool Approval

Read article
Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals image

Pest 5 Released With Test Impact Analysis, Agent Verification, and Evals

Read article
Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs image

Queue-SQL: Run Mass Deletes and Updates Across Parallel Queue Jobs

Read article
Blade Formatting in Laravel Pint image

Blade Formatting in Laravel Pint

Read article
Inertia DevTools Is Now on the Chrome Web Store image

Inertia DevTools Is Now on the Chrome Web Store

Read article