PHPackages                             sourcetoad/rule-helper-for-laravel - 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. sourcetoad/rule-helper-for-laravel

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

sourcetoad/rule-helper-for-laravel
==================================

Rule helper for Laravel

v6.3.0(3mo ago)9175.3k—4.2%12MITPHPPHP ^8.2||^8.3||^8.4||^8.5CI passing

Since Feb 22Pushed 5d ago7 watchersCompare

[ Source](https://github.com/sourcetoad/rule-helper-for-laravel)[ Packagist](https://packagist.org/packages/sourcetoad/rule-helper-for-laravel)[ RSS](/packages/sourcetoad-rule-helper-for-laravel/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (10)Versions (27)Used By (2)

Rule Helper for Laravel
=======================

[](#rule-helper-for-laravel)

Adds helpers to make building Laravel rule arrays easier by providing helper methods for the built-in rules.

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

[](#installation)

```
composer require sourcetoad/rule-helper-for-laravel
```

Usage
-----

[](#usage)

### RuleSet

[](#ruleset)

The `RuleSet` class provides a fluent interface for defining sets of rules.

#### Basic usage

[](#basic-usage)

```
use App\Rules\CustomRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Unique;
use Sourcetoad\RuleHelper\RuleSet;

class CreateBlogRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'title' => RuleSet::create()
                ->required()
                ->unique('posts', 'title', fn(Unique $rule) => $rule->withoutTrashed())
                ->rule(new CustomRule)
                ->max(255),
            'body' => RuleSet::create()
                ->required(),
        ];
    }
}
```

### Rule

[](#rule)

The `Rule` class provides the same methods as the Laravel `\Illuminate\Validation\Rule` class, with the rest of the built-in rules exposed via static methods.

#### Basic usage

[](#basic-usage-1)

```
use Illuminate\Foundation\Http\FormRequest;
use Sourcetoad\RuleHelper\Rule;

class CreateBlogRequest extends FormRequest
{
    public function rules(): array
    {
        return [
            'title' => [
                Rule::required(),
                Rule::unique('posts'),
                Rule::max(255),
            ],
            'body' => [
                Rule::required(),
            ],
        ];
    }
}
```

### Additional helpers

[](#additional-helpers)

#### Defined rule sets

[](#defined-rule-sets)

The `RuleSet` class contains methods to define and reuse rule sets across the project.

To define a rule set call `RuleSet::define` in your app service provider's boot method.

```
    public function boot(): void
    {
        RuleSet::define('existing_email', RuleSet::create()->email()->exists('users'));
    }
```

The defined set can then be used in rules using `RuleSet::useDefined`.

```
    public function rules(): array
    {
        return [
            'to' => RuleSet::useDefined('existing_email')->required(),
            'bcc' => RuleSet::useDefined('existing_email'),
        ];
    }
```

To concatenate a defined rule set you can call concatDefined with the rule set's name.

```
RuleSet::create()->required()->concatDefined('existing_email');
```

#### requiredIfAll

[](#requiredifall)

Accepts multiple `RequiredIf` rules and only marks as required if all return true.

#### requiredIfAny

[](#requiredifany)

Accepts multiple `RequiredIf` rules and marks as required if any return true.

Version Compatibility
---------------------

[](#version-compatibility)

LaravelRule Helper13.x6.3.x12.x6.x11.x5.x10.x4.x9.x3.x9.x2.x8.x1.x

###  Health Score

61

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity40

Moderate usage in the ecosystem

Community23

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 87.6% 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 ~64 days

Recently: every ~99 days

Total

24

Last Release

103d ago

Major Versions

v1.0.0 → v2.0.02022-04-30

v2.0.0 → v3.0.02022-12-23

v3.2.1 → v4.0.02023-08-23

v4.3.0 → v5.0.02024-03-13

v5.6.0 → v6.0.02025-02-24

PHP version history (6 changes)v1.0.0PHP ^7.4|^8.0

v2.0.0PHP ^8.0

v4.0.0PHP ^8.1

v5.0.0PHP ^8.2

v5.5.0PHP ^8.2||^8.3||^8.4

v6.3.0PHP ^8.2||^8.3||^8.4||^8.5

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1489473?v=4)[Sourcetoad](/maintainers/sourcetoad)[@sourcetoad](https://github.com/sourcetoad)

---

Top Contributors

[![erik-perri](https://avatars.githubusercontent.com/u/46399654?v=4)](https://github.com/erik-perri "erik-perri (226 commits)")[![Jasonej](https://avatars.githubusercontent.com/u/43227214?v=4)](https://github.com/Jasonej "Jasonej (21 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![iBotPeaches](https://avatars.githubusercontent.com/u/611784?v=4)](https://github.com/iBotPeaches "iBotPeaches (3 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")

---

Tags

laravelruleset

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/sourcetoad-rule-helper-for-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/sourcetoad-rule-helper-for-laravel/health.svg)](https://phpackages.com/packages/sourcetoad-rule-helper-for-laravel)
```

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17878.9k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

592.7k2](/packages/crumbls-layup)[team-nifty-gmbh/tall-datatables

Server-side rendered datatables for Laravel and Livewire

1320.9k4](/packages/team-nifty-gmbh-tall-datatables)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.4k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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