PHPackages                             darwinnatha/laravel-process - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. darwinnatha/laravel-process

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

darwinnatha/laravel-process
===========================

A Laravel micro-package based on the pipeline-task pattern for sequential business processes.

V1.0.0(10mo ago)0540MITPHPPHP ^8.0CI failing

Since Jun 22Pushed 10mo agoCompare

[ Source](https://github.com/darwinnatha/laravel-process)[ Packagist](https://packagist.org/packages/darwinnatha/laravel-process)[ RSS](/packages/darwinnatha-laravel-process/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (7)Versions (3)Used By (0)

Laravel Process
===============

[](#laravel-process)

A **completely flexible** and **customizable** process orchestration package for Laravel.
Structure your business logic as **processes** composed of **tasks** with **total control** over the base implementation.

---

✨ Key Philosophy
----------------

[](#-key-philosophy)

**Ultimate Flexibility** - **Publish and customize everything**:

- 📥 **Universal Input** - Accept any type: Arrays, Objects, Collections, Requests, DTOs, etc.
- 📤 **Universal Output** - Return any type: Boolean, Array, DTO, Resource, Collection, null, etc.
- 🎛️ **Customizable Base Class** - Publish AbstractProcess and modify it as needed
- 🚀 **Zero Constraints** - No forced patterns, complete developer freedom

---

✨ Features
----------

[](#-features)

- **Publishable Base Class** - Customize AbstractProcess to your needs
- **Universal Input/Output** - `mixed` types for maximum flexibility
- **Pipeline-Based** - Leverages Laravel's `Pipeline` for task chaining
- **Automatic Transactions** - Built-in DB transaction handling with rollback
- **Optional API Formatting** - Use `FormatsApiResponse` trait when needed
- **Artisan Commands** - Generate processes and tasks easily

---

📦 Installation
--------------

[](#-installation)

```
composer require darwinnatha/laravel-process
```

---

🚀 Quick Start
-------------

[](#-quick-start)

### 1. Publish the AbstractProcess (Recommended)

[](#1-publish-the-abstractprocess-recommended)

```
php artisan process:publish
```

This creates `app/Processes/AbstractProcess.php` that you can customize:

- Add logging, monitoring, caching
- Modify transaction handling
- Add middleware or custom validation
- Implement your error handling strategy

### 2. Create a Process

[](#2-create-a-process)

```
php artisan make:process CreateUserProcess --group=User
```

### 3. Create Tasks

[](#3-create-tasks)

```
php artisan make:task ValidateUserData --group=User
php artisan make:task SaveUserToDatabase --group=User
```

---

🧠 How It Works
--------------

[](#-how-it-works)

After publishing, your **AbstractProcess** becomes completely yours to customize. All processes extend from **your** base class.

### Example: Customized AbstractProcess

[](#example-customized-abstractprocess)

```
// app/Processes/AbstractProcess.php
abstract class AbstractProcess
{
    public array $tasks = [];

    public function handle(mixed $input): mixed
    {
        // Your custom logging
        Log::info('Process started', ['process' => static::class]);

        // Your custom validation
        $this->validateInput($input);

        // Your custom transaction handling
        DB::beginTransaction();
        try {
            $result = Pipeline::send($input)
                ->through($this->getMiddleware())  // Your middleware
                ->through($this->tasks)
                ->thenReturn();

            DB::commit();

            // Your custom success handling
            $this->onSuccess($result);
            return $result;

        } catch (Throwable $e) {
            DB::rollBack();

            // Your custom error handling
            $this->onError($e);
            throw $e;
        }
    }

    // Your custom methods
    protected function validateInput(mixed $input): void { /* ... */ }
    protected function getMiddleware(): array { return []; }
    protected function onSuccess(mixed $result): void { /* ... */ }
    protected function onError(Throwable $e): void { /* ... */ }
}
```

### Example: Your Process

[](#example-your-process)

```
namespace App\Processes\User;

use App\Processes\AbstractProcess;  // Your custom base class

class CreateUserProcess extends AbstractProcess
{
    public array $tasks = [
        Tasks\ValidateUserData::class,
        Tasks\SaveUserToDatabase::class,
        Tasks\SendWelcomeEmail::class,
    ];
}
```

### Example: Flexible Task

[](#example-flexible-task)

```
final class ValidateUserData implements TaskInterface
{
    public function __invoke(mixed $input, callable $next): mixed
    {
        // Handle any input type
        $data = match(true) {
            $input instanceof Request => $input->validated(),
            is_array($input) => $input,
            is_object($input) => (array) $input,
            default => throw new InvalidArgumentException('Unsupported input')
        };

        // Your validation logic
        if (!$this->isValid($data)) {
            throw new ValidationException('Invalid data');
        }

        return $next($input);
    }
}
```

---

🚀 Usage Examples
----------------

[](#-usage-examples)

### With Different Input Types

[](#with-different-input-types)

```
$process = new CreateUserProcess();

// With an array
$result = $process->handle(['name' => 'John', 'email' => 'john@test.com']);

// With a Request
$result = $process->handle($request);

// With a DTO
$result = $process->handle($userDto);

// With any custom object
$result = $process->handle($customObject);
```

---

🎛️ Optional API Response Formatting
-----------------------------------

[](#️-optional-api-response-formatting)

If you want standardized API responses, use the **optional** `FormatsApiResponse` trait:

```
use DarwinNatha\Process\Traits\FormatsApiResponse;

final class CreateUserTask implements TaskInterface
{
    use FormatsApiResponse; // Optional!

    public function __invoke(mixed $input, callable $next): mixed
    {
        try {
            $user = User::create($this->extractData($input));
            return $this->created($user, 'User created successfully');
        } catch (Exception $e) {
            return $this->error('User creation failed', ['error' => $e->getMessage()]);
        }
    }
}
```

**This is completely optional** - by default, return whatever you want!

---

⚙️ Commands
-----------

[](#️-commands)

### Publish AbstractProcess

[](#publish-abstractprocess)

```
php artisan process:publish          # Publish for customization
php artisan process:publish --force  # Overwrite existing
```

### Generate Classes

[](#generate-classes)

```
php artisan make:process LoginProcess --group=Auth
php artisan make:task ValidateCredentials --group=Auth
```

---

🎯 Advanced Customization Examples
---------------------------------

[](#-advanced-customization-examples)

### Add Caching to Your AbstractProcess

[](#add-caching-to-your-abstractprocess)

```
public function handle(mixed $input): mixed
{
    $cacheKey = $this->getCacheKey($input);

    if ($cacheKey && Cache::has($cacheKey)) {
        return Cache::get($cacheKey);
    }

    $result = $this->executeProcess($input);

    if ($cacheKey) {
        Cache::put($cacheKey, $result, $this->getCacheTtl());
    }

    return $result;
}
```

---

🧪 Testing
---------

[](#-testing)

Run tests:

```
vendor/bin/pest
```

The package includes comprehensive tests covering:

- AbstractProcess publication and customization
- Flexible input/output handling
- Different data types (arrays, objects, DTOs, Requests)
- Transaction rollback on failures
- Console command generation

---

🧑‍💻 Author
----------

[](#‍-author)

**Darwin Piegue (DarwinNatha)**🔗 [github.com/darwinnatha](https://github.com/darwinnatha)

---

⚖️ License
----------

[](#️-license)

MIT License — free to use, modify, and distribute.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance53

Moderate activity, may be stable

Popularity13

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

322d ago

Major Versions

V1.0.0 → v2.0.0-beta2025-06-22

### Community

Maintainers

![](https://www.gravatar.com/avatar/7e36313b007c24352d7698e140f37040859bc039d50682ccf3822f94fc042718?d=identicon)[darwinnatha](/maintainers/darwinnatha)

---

Top Contributors

[![darwinnatha](https://avatars.githubusercontent.com/u/136787768?v=4)](https://github.com/darwinnatha "darwinnatha (17 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/darwinnatha-laravel-process/health.svg)

```
[![Health](https://phpackages.com/badges/darwinnatha-laravel-process/health.svg)](https://phpackages.com/packages/darwinnatha-laravel-process)
```

###  Alternatives

[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)[laragear/preload

Effortlessly make a Preload script for your Laravel application.

119363.5k](/packages/laragear-preload)[glhd/conveyor-belt

14797.0k](/packages/glhd-conveyor-belt)[napp/xray-laravel

AWS X-Ray for Laravel applications.

61407.3k](/packages/napp-xray-laravel)[dragon-code/pretty-routes

Pretty Routes for Laravel

10058.7k4](/packages/dragon-code-pretty-routes)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
