darwinnatha / laravel-process
Un micro-package Laravel basé sur le pattern pipeline-task pour les processus métier séquentiels.
Requires
- php: ^8.0
- illuminate/console: ^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/contracts: *
- illuminate/http: ^8.0|^9.0|^10.0|^11.0|^12.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: *
- pestphp/pest: *
This package is auto-updated.
Last update: 2025-06-14 18:26:20 UTC
README
A lightweight and elegant pipeline-based process orchestration package for Laravel.
It lets you structure your business logic as processes composed of tasks, with built-in error handling, automatic transactions, and a consistent return format.
✨ Features
- Organize logic into processes and tasks
- Leverages Laravel's
Pipeline
for task chaining - Automatically handles transactions and error catching
- Unified response structure:
code
,status
,message
,data
- Artisan commands to generate process and task classes
- Stub-based generation for easy customization
ProcessorTrait
for seamless controller integration
📦 Installation
Note: The package name (
darwinnatha/laravel-process
) matches the repository name for clarity.
composer require darwinnatha/laravel-process
🧠 How It Works
A Process is a class that chains a set of Tasks using Laravel’s pipeline.
Example: LoginProcess
namespace App\Processes\Auth; class LoginProcess extends AbstractProcess { public array $tasks = [ Tasks\DetermineUser::class, Tasks\GenerateToken::class, Tasks\FinalizeLogin::class, ]; }
Each Task is a single-purpose class that implements __invoke(Request $request, Closure $next)
.
final class DetermineUser { public function __invoke(Request $request, Closure $next): mixed { $user = User::where('phone_number', $request->phone_number)->first(); if (! $user) { return [ 'code' => 404, 'status' => 'error', 'message' => 'User not found', ]; } $request->merge(['user_id' => $user->id]); return $next($request); } }
🧰 Using a Process in Controllers
Use the ProcessorTrait
to cleanly run a process and handle the response:
use DarwinNatha\Process\Traits\ProcessorTrait; class AuthController extends Controller { use ProcessorTrait; public function login(LoginRequest $request) { [$code, $result] = $this->runProcess(LoginProcess::class, $request); return response()->json($result, $code); } }
⚙️ Generate Classes
Create a process or a task with:
php artisan make:process LoginProcess --group=Auth php artisan make:task DetermineUser --group=Auth
If
--group
or--name
is not passed, the command will interactively ask for the values.
This creates:
app/Processes/Auth/LoginProcess.php
app/Processes/Auth/Tasks/DetermineUser.php
Missing folders are automatically created and capitalized properly.
Use --force
to overwrite existing files, or you'll be prompted.
🧪 Testing
The package includes full feature testing using:
- ✅ PestPHP
- 🔁 Mockery
- 🧪 Orchestra Testbench
Run tests with:
vendor/bin/pest
Tests cover:
- Process execution and flow
- Task chaining and modification
- Console command behavior and file generation
🧑💻 Author
Darwin Piegue (DarwinNatha) 🔗 github.com/darwinnatha
⚖️ License
MIT License — free to use, modify, and distribute.