PHPackages                             yeashy/compliance - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. yeashy/compliance

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

yeashy/compliance
=================

Pipeline Validation For Laravel Apps

v1.0.0-stable(9mo ago)11588MITPHPPHP ^8.1

Since Jun 1Pushed 9mo ago1 watchersCompare

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

READMEChangelog (9)Dependencies (3)Versions (10)Used By (0)

Yeashy Compliance
=================

[](#yeashy-compliance)

[![Latest Version on Packagist](https://camo.githubusercontent.com/776dff92e623d77f4cbd59e6e7d9fc8ffcf9e8d28dc5afb670fd876b334746f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7965617368792f636f6d706c69616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yeashy/compliance)[![Total Downloads](https://camo.githubusercontent.com/7ca5b32ab9bc13d361a7103cf8a404b4249b74e7ec798975dbc0c0de9bb85845/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7965617368792f636f6d706c69616e63652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/yeashy/compliance)[![License](https://camo.githubusercontent.com/3bc3c89785c2a40716403921d89081fee3f308024082e7c692f62a812c140e68/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7965617368792f636f6d706c69616e63652e7376673f7374796c653d666c61742d737175617265)](https://github.com/yeashy/compliance/blob/main/LICENSE)

**Yeashy Compliance** is an elegant pipeline-based validation system for Laravel, designed to extend `FormRequest` validation with domain-driven, reusable, and expressive rule objects.

---

🚀 Features
----------

[](#-features)

- ✅ Seamless integration with Laravel `FormRequest`
- 🧩 Pipeline-based rule processing
- 🎯 HTTP-method-specific rule handling (`GET`, `POST`, etc.)
- 🔁 Composable and testable rule classes
- 📦 Fully compatible with standard Laravel validation

---

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

[](#-installation)

Install the package via Composer:

```
composer require yeashy/compliance
```

No additional service provider registration is required.

🧑‍💻 Getting Started
-------------------

[](#‍-getting-started)

To use Compliance in your requests, simply extend the base `ComplianceRequest` instead of Laravel’s `FormRequest`.

### Step 1: Create a Compliance Rule

[](#step-1-create-a-compliance-rule)

A compliance rule is a class that extends `Yeashy\Compliance\Rules\ComplianceRule` and implements the `validate()` method.

```
use Yeashy\Compliance\Rules\ComplianceRule;

class EmailIsNotBlocked extends ComplianceRule
{
    protected string $key = 'email';
    protected string $message = 'This email address is blocked.';

    protected function validate(): void
    {
        if ($this->data->email === 'blocked@example.com') {
            $this->invalidateAndExit(); // Add error and stop the pipeline
        }
    }
}
```

### Step 2: Apply the Rule in a Request

[](#step-2-apply-the-rule-in-a-request)

Extend `ComplianceRequest` and define the rules in the `$compliances` property, or specify them per HTTP method (`$postCompliances`, `$getCompliances`, etc.).

```
use Yeashy\Compliance\Requests\ComplianceRequest;

class RegisterRequest extends ComplianceRequest
{
    protected array $postCompliances = [
        \App\Compliance\Rules\EmailIsNotBlocked::class,
    ];

    public function rules(): array
    {
        return [
            'email' => ['required', 'email'],
            'password' => ['required'],
        ];
    }
}
```

That’s it! The request will now go through both Laravel’s standard validation and your custom compliance pipeline.

⚙️ How Compliance Rules Work
----------------------------

[](#️-how-compliance-rules-work)

Each rule receives an object containing:

- All input data from the request `(Request::all())`
- Route parameters

The `validate()` method inside each rule is executed in sequence. You can:

- Use `invalidate($key, $message)` to add an error and continue to the next rule.
- Use `invalidateAndExit()` to add an error and stop the pipeline immediately.
- Use `skipNext()` to stop the pipeline without adding an error (optional shortcut).

### HTTP Method Specific Rules

[](#http-method-specific-rules)

Compliance rules can be defined globally for all methods:

```
protected array $compliances = [...];`
```

Or scoped to specific HTTP verbs:

```
protected array $postCompliances = [...];
protected array $getCompliances = [...];
// Supported: get, post, put, patch, delete, head, options
```

### Error Merging

[](#error-merging)

Compliance errors are automatically merged with Laravel’s validation errors and returned in the standard format. If a compliance rule sets a custom `$statusCode`, it will override the default HTTP 422 status.

✅ Best Practices
----------------

[](#-best-practices)

- Rules should follow the Single Responsibility Principle: one rule — one concern.
- Use meaningful keys (`$key`) to ensure correct field mapping in error responses.
- Localize messages using `__('...')` whenever possible.
- Prefer `invalidateAndExit()` for critical rules (e.g., credential checks).
- Use `skipNext()` if the current rule makes the remaining ones irrelevant.

📂 Example
---------

[](#-example)

Rule: Ensure the user is not blocked

```
use Illuminate\Support\Facades\Auth;
use Yeashy\Compliance\Rules\ComplianceRule;

class UserIsNotBlocked extends ComplianceRule
{
    protected string $key = 'user';
    protected string $message = 'Your account has been blocked.';
    public int $statusCode = 403;

    protected function validate(): void
    {
        $user = Auth::user();

        if (! $user || $user->is_blocked) {
            $this->invalidateAndExit();
        }
    }
}
```

### Usage in Request:

[](#usage-in-request)

```
use Yeashy\Compliance\Requests\ComplianceRequest;

class DashboardRequest extends ComplianceRequest
{
    protected array $compliances = [
        \App\Compliance\Rules\UserIsNotBlocked::class,
        \App\Compliance\Rules\AccountIsVerified::class,
    ];

    protected array $getCompliances = [
        \App\Compliance\Rules\SubscriptionIsActive::class,
        \App\Compliance\Rules\UserHasAccessToResource::class,
    ];

    public function rules(): array
    {
        return [
            'resource_id' => ['required', 'uuid'],
        ];
    }
}
```

In this example:

- `$compliances` defines global rules that apply to all HTTP methods.
- `$getCompliances` defines additional rules applied only for `GET` requests.
- All rules are processed in order, and execution stops if a rule uses `invalidateAndExit()`.

🧪 Testing
---------

[](#-testing)

You can test compliance rules in isolation:

```
public function test_email_is_not_blocked()
{
    $rule = new EmailIsNotBlocked();

    $data = (object) ['email' => 'blocked@example.com'];

    $rule->handle($data, fn($data) => $data);

    $this->assertNotEmpty($data->__errorMessages);
}
```

📄 License
---------

[](#-license)

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

🤝 Contributing
--------------

[](#-contributing)

Contributions, issues and feature requests are welcome! Feel free to submit a PR or open an issue.

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance58

Moderate activity, may be stable

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Recently: every ~3 days

Total

9

Last Release

273d ago

Major Versions

v0.0.9-stable → v1.0.0-stable2025-08-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/2a4ec533795b3f568e9345f99847e9d45376b834ccf4dd53587ca5fdfafe1505?d=identicon)[yeashy](/maintainers/yeashy)

---

Top Contributors

[![yeashy](https://avatars.githubusercontent.com/u/80777936?v=4)](https://github.com/yeashy "yeashy (6 commits)")

---

Tags

laravellaravel-packagephppipelinevalidation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/yeashy-compliance/health.svg)

```
[![Health](https://phpackages.com/badges/yeashy-compliance/health.svg)](https://phpackages.com/packages/yeashy-compliance)
```

###  Alternatives

[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1036.7k3](/packages/carsdotcom-laravel-json-schema)

PHPackages © 2026

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