PHPackages                             istvan0304/laravel-workflow - 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. istvan0304/laravel-workflow

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

istvan0304/laravel-workflow
===========================

Laravel workflow engine.

1.4.0(3y ago)0191MITPHPPHP &gt;=7.4

Since Feb 15Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (7)Used By (0)

Laravel workflow
================

[](#laravel-workflow)

### Installion

[](#installion)

composer require istvan0304/laravel-workflow

### Configuration

[](#configuration)

#### Attach Workflow behavior into your Model.

[](#attach-workflow-behavior-into-your-model)

```
use Istvan0304\Workflow\WorkflowTrait;

class BlogPost extends Model
{
    use WorkflowTrait;

    /**
     * @var string
     */
    protected string $workflowClass = BlogPostWorkflow::class;

```

#### Default workflow attribute is "status" but you can overwrite it in your Model like:

[](#default-workflow-attribute-is-status-but-you-can-overwrite-it-in-your-model-like)

```
protected string $customWorkflowStatusAttribute = 'state';

```

#### Add observer to the EventServiceProvider:

[](#add-observer-to-the-eventserviceprovider)

```
protected $observers = [
        BlogPost::class => [\Istvan0304\Workflow\Observers\WorkflowObserver::class],
    ];

```

### Create a workflow

[](#create-a-workflow)

A workflow is defined as a PHP class that implements the `Istvan0304\Workflow\WorkflowDefinition` interface which declares three functions:

> - statusLabels() // This method must return an array representing the workflow status names.
> - statusActionLabels() // This method must return an array representing the workflow status action names.
> - getDefinition() // This method must return an array representing the workflow definition.

Example workflow class:

```
namespace App\Models;

use Illuminate\Support\Facades\Auth;
use Istvan0304\Workflow\WorkflowDefinition;

class BlogPostWorkflow implements WorkflowDefinition
{
    const DRAFT = 'draft';
    const DELETED = 'deleted';
    const FINAL = 'final';
    const REJECT = 'reject';
    const FIX = 'fix';
    const PUBLISHED = 'published';

    /**
     * @return string[]
     */
    public static function statusLabels(): array
    {
        return [
            self::DRAFT => 'Draft',
            self::DELETED => 'Deleted',
            self::FINAL => 'Finalized',
            self::REJECT => 'Rejected',
            self::FIX => 'Returned for repair',
            self::PUBLISHED => 'Published'
        ];
    }

    /**
     * @return string[]
     */
    public static function statusActionLabels(): array
    {
        return [
            self::DRAFT => 'Draft',
            self::DELETED => 'Delete',
            self::FINAL => 'Finalization',
            self::REJECT => 'Rejection',
            self::FIX => 'Return for repair',
            self::PUBLISHED => 'Publication'
        ];
    }

    /**
     * @return array
     */
    public static function getDefinition(): array
    {
        return [
            'initialStatus' => self::DRAFT,
            'status' => [
                self::DRAFT => [
                    'transition' => [self::FINAL, self::DELETED],
//                    'transition' => function(){
//                        return [self::REJECT, self::FIX];
//                    },
                ],
                self::DELETED => [
                    'transition' => [],
                ],
                self::FINAL => [
                    'transition' => (Auth::user()->hasRole('admin') ? [self::DELETED, self::REJECT, self::FIX, self::PUBLISHED] : [self::REJECT, self::FIX, self::PUBLISHED]),
                ],
                self::REJECT => [
                    'transition' => [],
                ],
                self::FIX => [
                    'transition' => [self::FINAL],
                ],
                self::PUBLISHED => [
                    'transition' => [],
                ]
            ]
        ];
    }
}

```

### Start workflow

[](#start-workflow)

```
/**
     * Create blog post
     * @param Request $request
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
     */
    public function createStore(Request $request)
    {
        $model = new BlogPost();

        // ...

        $model->start();     // Workflow start
        $model->fill($attributes);

        if ($model->save()) {
            return redirect('/blog-posts')->with('message', 'Successfully saved!');
        }
    }

```

### Change status

[](#change-status)

```
/**
     * @param Request $request
     * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|void
     */
    public function updateStore(Request $request, $id)
    {
        $model = BlogPost::find($id);

        // ...

        if($request->final){
            $model->sendToStatus(BlogPostWorkflow::FINAL);  // Change status
        }

        // ...
    }

```

If no transition between two status you are going to get an Exception.

### License

[](#license)

The MIT License (MIT). Please see License File for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 75% 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

6

Last Release

1180d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f6a9e8aa5de8d9824a754adf171efc1ff713767cd9ead2e2aceb5eaeb4b2244e?d=identicon)[istvan0304](/maintainers/istvan0304)

---

Top Contributors

[![istvan0304](https://avatars.githubusercontent.com/u/19621571?v=4)](https://github.com/istvan0304 "istvan0304 (6 commits)")[![steve0304pte](https://avatars.githubusercontent.com/u/242409783?v=4)](https://github.com/steve0304pte "steve0304pte (2 commits)")

---

Tags

laravelworkflow

### Embed Badge

![Health badge](/badges/istvan0304-laravel-workflow/health.svg)

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

###  Alternatives

[brexis/laravel-workflow

Integerate Symfony Workflow component into Laravel.

283125.6k](/packages/brexis-laravel-workflow)[tarfin-labs/event-machine

Event-driven state machines for Laravel with event sourcing, type-safe context, and full audit trail.

188.5k](/packages/tarfin-labs-event-machine)

PHPackages © 2026

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