PHPackages                             luminee/validator - 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. luminee/validator

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

luminee/validator
=================

Enhanced validator for laravel

0.5.5.1(11mo ago)010MITPHPPHP &gt;=7.0

Since Jun 20Pushed 11mo agoCompare

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

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Luminee Validator - Laravel 增强验证器
=================================

[](#luminee-validator---laravel-增强验证器)

安装
--

[](#安装)

```
composer require luminee/validator
```

快速开始
----

[](#快速开始)

### 1. 创建验证请求

[](#1-创建验证请求)

```
php artisan validator:make-request CustomRequest
```

生成的请求类将继承 `Luminee\Validator\Requests\BaseRequest`

若使用模块化项目，请自行将生成的 `CustomRequest.php` 文件移动到对应的目录中

### 2. 定义验证规则

[](#2-定义验证规则)

```
const NAME = 'required|max:50';

public function rules()
{
    return array_merge(parent::rules(), [
        //
        'name' => self::NAME,
        'brothers' => 'required|between:0,10',
        'sisters' => ['required', 'between:0,10'],
        'age' => [self::required(), self::between(1, 150)]
    ]);
}
```

上面四种方式均可

1. 在 `BaseRequest` 或当前类中配置常用常量
2. 直接使用官方的字符串方式
3. 直接使用官方的数组方式
4. 使用配置好的规则方法的数组形式

`messages()` 和 `attributes()` 同样使用官方的方式在 `BaseRequst` 或当前类配置

### 3. 自定义验证规则

[](#3-自定义验证规则)

```
php artisan validator:make-rule CustomRule
```

规则文件将生成在 `app/Http/Requests/Rules/` 目录，实现 `passes()` 和 `message()` 方法即可

如果使用了模块化项目，需自行将生成的 `CustomRule.php` 文件移动到对应的目录中

使用自定义规则：

```
return array_merge(parent::rules(), [
    'reward' => ['required', new CustomRule()],
]);
```

### 4. 验证请求

[](#4-验证请求)

```
use App\Http\Requests\CustomRequest;

$validator = Validator::validate(CustomRequest::class);
if ($validator->fails())
    return response()->json(['error' => $validator->messages()->first()], 422);

// 获取验证后的参数
$params = $validator->getData();
// 或
$params = $this->all();
```

### 动态改写验证规则

[](#动态改写验证规则)

```
$request = app()->make(CustomRequest::class);
$validator = Validator::validate($request, [
    'user_id' => 'required|between:1,100',
    'age' => [$request->required(), $request->between(18, 100)],
], [
    'required' => ':attribute 字段不能为空'
], [
    'user_id' => '用户ID'
]);
```

参数说明：

1. 第一个参数可以是类名或请求实例
2. 参数2-4分别对应 `rules()`, `messages()`, `attributes()` 的改写

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance52

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity22

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

332d ago

### Community

Maintainers

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

---

Top Contributors

[![Luminee](https://avatars.githubusercontent.com/u/17894745?v=4)](https://github.com/Luminee "Luminee (3 commits)")

### Embed Badge

![Health badge](/badges/luminee-validator/health.svg)

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

###  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)
