PHPackages                             dbt/staged-validation - 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. dbt/staged-validation

ActiveProject

dbt/staged-validation
=====================

Staged validation for Laravel

3.0.0(4y ago)0525MITPHPPHP &gt;=8.0.0CI failing

Since Oct 22Pushed 4y ago1 watchersCompare

[ Source](https://github.com/DeBoerTool/staged-validation)[ Packagist](https://packagist.org/packages/dbt/staged-validation)[ Docs](https://github.com/dbt/staged-validation)[ RSS](/packages/dbt-staged-validation/feed)WikiDiscussions trunk Synced today

READMEChangelog (4)Dependencies (8)Versions (5)Used By (0)

Staged Validation for Laravel
=============================

[](#staged-validation-for-laravel)

This package provides an easy way to validate request data in stages. This is useful in cases where you want to validate, say, scalar data before doing heavy lifting against the database or external services.

This package also provides a convenient way to cache data in your `Rule` classes, so you don't have to look up records twice (eg once in a form request and again in a controller).

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

[](#installation)

```
composer require dbt/staged-validation
```

Usage
-----

[](#usage)

### Bundles

[](#bundles)

Define a set of stages by extending the abstract `StageBundle`. It should look something like this:

```
use Dbt\StagedValidation\StageBundle;

class MyBundle extends StageBundle
{
    /**
     * @return \Dbt\StagedValidation\StageInterface[]
     */
    public function stages (): array
    {
        return [
            new FirstStage(),
            new SecondStage(),
        ];
    }
}
```

### Stages

[](#stages)

Each stage should extend the abstract `Stage` class. Eg:

```
use Dbt\StagedValidation\Stage;

class FirstStage extends Stage
{
    public function name (): string
    {
        return 'first_stage';
    }

    public function rules (): array
    {
        return [
            'my_string' => [
                'required',
                'string',
                'min:10',
            ],
        ];
    }
}
```

### Validation

[](#validation)

Simply typehint the bundle in your controller:

```
class MyController {
    public function __invoke (MyBundle $bundle) {
        // Get all the validated data from each stage.
        $all = $bundle->all();

        // Get the validated data from a specific stage.
        $first = $bundle->get('first_stage');
    }
}
```

Each stage will be validated separately. This means if one stage fails validation, the next stage won't be run.

### Retaining entities

[](#retaining-entities)

If you wish to retain fetched entities, extend the `CachedRule` class. It's simply a Laravel `Rule` with a slightly different interface:

```
use Dbt\StagedValidation\CachedRule;

class RuleStub extends CachedRule
{
    public function message ()
    {
        return 'my failure message';
    }

    public function fetch ()
    {
        // Fetch from an external resource. Under the hood, whatever you
        // return here will be assigned to $this->cached.
    }

    protected function passesAfterFetch ($attribute, $value)
    {
        // Perform validation as you normally would, keeping in mind that
        // $this->cached has already been assigned.
        return $this->cached->someMethod() === $value;
    }
}
```

The retained entities will be serialized along with the original values as part of the bundle payload. So if a stage named `second_stage` has a cached rule for an attribute called `my_attribute`, you will be see a collection with this shape:

```
// $bundle->get('second_stage')->toArray()
[
    'second_stage' => [
        'my_attribute' => // the original data,
        'my_attribute_cached' => // the fetched entity
    ],
];
```

Extending
---------

[](#extending)

If you wish to write your own implementation, you may implement any of the provided interfaces: `CachedRuleInterface`, `StageBundleInterface`, or `StageInterface`.

If you wish to change the Validator implementation for a given stage, you may override the `Stage::validatorResolver()` method.

Etc.
----

[](#etc)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details. The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~188 days

Total

4

Last Release

1461d ago

Major Versions

1.0.0 → 2.0.02020-12-09

2.0.1 → 3.0.02022-05-09

PHP version history (4 changes)1.0.0PHP ^7.2

2.0.0PHP ^7.2.5

2.0.1PHP &gt;=7.2.5

3.0.0PHP &gt;=8.0.0

### Community

Maintainers

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

---

Top Contributors

[![danielsdeboer](https://avatars.githubusercontent.com/u/13170241?v=4)](https://github.com/danielsdeboer "danielsdeboer (23 commits)")

---

Tags

phplaraveldbt

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/dbt-staged-validation/health.svg)

```
[![Health](https://phpackages.com/badges/dbt-staged-validation/health.svg)](https://phpackages.com/packages/dbt-staged-validation)
```

###  Alternatives

[laracraft-tech/laravel-xhprof

Easy XHProf setup to profile your laravel application!

235321.4k](/packages/laracraft-tech-laravel-xhprof)[kompo/kompo

Laravel &amp; Vue.js FullStack Components for Rapid Application Development

11812.4k21](/packages/kompo-kompo)[bavix/laravel-xhprof

Quick profiling of your code for Laravel

22156.6k](/packages/bavix-laravel-xhprof)

PHPackages © 2026

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