PHPackages                             juststeveking/laravel-flows - 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. juststeveking/laravel-flows

ActiveLibrary

juststeveking/laravel-flows
===========================

A fluent, modular workflow builder for Laravel.

1.0.4(3mo ago)104182MITPHPPHP ^8.3CI failing

Since Feb 19Pushed 3mo ago2 watchersCompare

[ Source](https://github.com/JustSteveKing/laravel-flows)[ Packagist](https://packagist.org/packages/juststeveking/laravel-flows)[ Docs](https://github.com/juststeveking/laravel-flows)[ GitHub Sponsors](https://github.com/sponsors/juststeveking)[ RSS](/packages/juststeveking-laravel-flows/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (5)Dependencies (6)Versions (6)Used By (0)

Laravel Flows
=============

[](#laravel-flows)

[![PHP Version](https://camo.githubusercontent.com/14222773a8e7388dc0f10bcc09996b57217245915d92c5a568fdd4ce8866858f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6a75737473746576656b696e672f6c61726176656c2d666c6f77732e7376673f7374796c653d666c61742d737175617265)](https://php.net)[![Latest Version](https://camo.githubusercontent.com/ae2e4439b242118cac177d3a782ccf6b61a0106fe0d19f07f01028de6239a107/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a75737473746576656b696e672f6c61726176656c2d666c6f77732e7376673f7374796c653d666c61742d737175617265266c6162656c3d72656c65617365)](https://packagist.org/packages/juststeveking/laravel-flows)[![Tests](https://github.com/JustSteveKing/laravel-flows/actions/workflows/tests.yml/badge.svg)](https://github.com/JustSteveKing/laravel-flows/actions/workflows/tests.yml)[![Formats](https://github.com/JustSteveKing/laravel-flows/actions/workflows/formats.yml/badge.svg)](https://github.com/JustSteveKing/laravel-flows/actions/workflows/formats.yml)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](LICENSE)[![Total Downloads](https://camo.githubusercontent.com/5f0564baf4084bd5c1a2b2b77bf97e287795d770b86f0e786105e0060296587b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a75737473746576656b696e672f6c61726176656c2d666c6f77732e7376673f7374796c653d666c61742d73717561726526636f6c6f72423d6d656469756d76696f6c6574726564)](https://packagist.org/packages/juststeveking/laravel-flows)

A fluent, modular workflow builder for Laravel that leverages the Pipeline pattern to simplify and organize business logic.

Introduction
------------

[](#introduction)

Flows is a lightweight Laravel package designed to turn complex, multi-step business logic into an elegant, maintainable workflow. With a fluent API, you can easily chain steps, incorporate conditional logic, and keep your code modular and testable—perfect for any process that needs a well-orchestrated flow.

Features
--------

[](#features)

- **Fluent API**: Easily chain workflow steps using methods like `run()`, `branch()`, `chain()`, and the new `runIf()`.
- **Conditional Branches**: Integrate custom conditions using your own implementations of `FlowCondition`.
- **Testable &amp; Modular**: Each step is isolated, making it a breeze to unit test and maintain.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require juststeveking/laravel-flows
```

Usage
-----

[](#usage)

### Basic Usage

[](#basic-usage)

Create a simple workflow to process your payload:

```
use JustSteveKing\Flows\Flow;
use App\Flows\Steps\DummyStep;

$result = Flow::start()->run(
    action: DummyStep::class,
)->execute(
    payload: 'Initial payload',
);
```

### Advanced Workflow with Conditional Branches

[](#advanced-workflow-with-conditional-branches)

Leverage branch steps to conditionally execute parts of your workflow:

```
use JustSteveKing\Flows\Flow;
use App\Flows\Conditions\IsSupplier;
use App\Flows\Steps\CommonStep;
use App\Flows\Steps\SupplierStep;

$result = Flow::start()->run(
    action: CommonStep::class,
)->branch(
    condition: IsSupplier::class,
    callback: fn(array $payload): array => Flow::start()->run(
        action: SupplierStep::class,
    )->execute(payload: $payload),
)->execute(payload: $payload);
```

### Real-World Example: User Registration

[](#real-world-example-user-registration)

The workflow starts with basic tasks: validating the registration data, hashing the password, creating the user, and sending a welcome email.

It then uses a branch to conditionally run a sub-workflow (sending a VIP welcome email) if the condition `IsVIPUser` evaluates to `true`.

Finally, it logs the registration event before returning the processed data.

```
