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

acquaintsoft logo
Acquaint Softtech

Hire Laravel developers with AI expertise at $20/hr. Get started in 48 hours.

Visit Acquaint Softtech

The latest

View all →
Agent Run Observability in Laravel AI SDK 0.11 image

Agent Run Observability in Laravel AI SDK 0.11

Read article
Debounced Queued Event Listeners in Laravel image

Debounced Queued Event Listeners in Laravel

Read article
Statamic Mailables Viewer Previews Laravel Emails in the Control Panel image

Statamic Mailables Viewer Previews Laravel Emails in the Control Panel

Read article
Laravel Tackle: Run an AI Coding Agent in Your Laravel App image

Laravel Tackle: Run an AI Coding Agent in Your Laravel App

Read article
Queue::forward(): Reroute Laravel Queues in One Place image

Queue::forward(): Reroute Laravel Queues in One Place

Read article
Laravel Read-Through Filesystem: Lazy Storage Migration image

Laravel Read-Through Filesystem: Lazy Storage Migration

Read article