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(1y ago)040MITPHPPHP &gt;=7.0

Since Jun 20Pushed 1y agoCompare

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

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

23

—

LowBetter than 26% of packages

Maintenance49

Moderate activity, may be stable

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity23

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

379d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/17894745?v=4)[LuminEe](/maintainers/LuminEe)[@Luminee](https://github.com/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

[unopim/unopim

UnoPim Laravel PIM

10.5k2.4k](/packages/unopim-unopim)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[ecotone/laravel

Ecotone for Laravel — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Laravel Queue, via PHP attributes.

21318.6k3](/packages/ecotone-laravel)[duncanmcclean/statamic-cargo

Comprehensive e-commerce addon for Statamic. Build bespoke e-commerce sites without the complexity.

3416.9k](/packages/duncanmcclean-statamic-cargo)[carsdotcom/laravel-json-schema

Json Schema validation for Laravel projects

1043.3k6](/packages/carsdotcom-laravel-json-schema)

PHPackages © 2026

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