PHPackages                             starrysea/validate - 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. starrysea/validate

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

starrysea/validate
==================

Laravel routing parameter validation, form validation extension

1.0.2(7y ago)030MITPHPPHP ^7.0

Since Dec 8Pushed 7y agoCompare

[ Source](https://github.com/caixingyue/laravel-starrysea-validate)[ Packagist](https://packagist.org/packages/starrysea/validate)[ Docs](https://github.com/caixingyue/laravel-starrysea-validate)[ RSS](/packages/starrysea-validate/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (4)Used By (0)

安装
--

[](#安装)

- [Laravel](#laravel)
- [Lumen](#lumen)

### Laravel

[](#laravel)

该软件包可用于 Laravel 5.6 或更高版本。

您可以通过 composer 安装软件包：

```
composer require starrysea/validate
```

在 Laravel 5.6 中，服务提供商将自动注册。在旧版本的框架中，只需在 `config/app.php` 文件中添加服务提供程序：

```
'providers' => [
    // ...
    Starrysea\Validate\ValidateServiceProvider::class,
];

'aliases' => [
    // ...
    'Validate' => Starrysea\Validate\Validate::class,
];
```

### Lumen

[](#lumen)

您可以通过 composer 安装软件包：

```
composer require starrysea/validate
```

注册服务提供者和门面：

```
$app->register(Starrysea\Validate\ValidateServiceProvider::class); // 注册 Validate 服务提供者

class_alias(Starrysea\Validate\Validate::class, 'Validate'); // 添加 Validate 门面
```

用法
--

[](#用法)

```
// app/Providers/RouteServiceProvider.php

use Starrysea\Validate\Validate;

class RouteServiceProvider
{
    // ...

    public function boot()
    {
        Validate::RoutesParameter(); // 定义路由参数验证
        // ...
    }

    // ...
}
```

```
// routes/web.php

// 验证 id/ids
Route::get('/{id}', function ($id) {
    return $id; // 纯数字通过, 否则 404 错误
});

// 验证手机号码
Route::get('/{phone}', function ($phone) {
    return $phone; // 中国11位手机号码通过, 否则 404 错误
});

// 验证多id, 以","号分隔, 如: 1,2,3,4,5
Route::get('/{manyid}', function ($manyid) {
    return $manyid; // 全部都为数字通过, 否则 404 错误
});
```

```
// app/Providers/AppServiceProvider.php

use Starrysea\Validate\Validate;

class AppServiceProvider
{
    // ...

    public function boot()
    {
        Validate::FormRules(); // 扩展表单验证规则
        // ...
    }

    // ...
}
```

```
// resources/lang/en/validation.php

return [
    // ...

    'identitys' => 'The :attribute not a valid id number.',

    'phone' => 'The :attribute not a legal chinese mobile number.',

    'english' => 'The :attribute contains characters other than spaces, english, and numbers.',

    'password' => 'The :attribute does not meet the password verification rules.',
];

// resources/lang/zh_cn/validation.php

return [
    // ...

    'identitys' => ':attribute 不是合法的身份证号码',

    'phone' => ':attribute 不是合法的中国手机号码',

    'english' => ':attribute 包含了空格、英文、数字以外的字符',

    'password' => ':attribute 不符合密码验证规则',
];
```

```
// vendor/laravel/framework/src/Illuminate/Foundation/Http/FormRequest.php

use Starrysea\Validate\FormRequest as FormRequestDevelop;

class FormRequest
{
    // ...

    // 引入表单验证扩展
    use FormRequestDevelop;

    // 重写创建验证实例方法
    protected function createDefaultValidator(ValidationFactory $factory)
    {
        return $factory->make(
            $this->validationData(), $this->container->call([$this, 'combine']),
            $this->messages(), $this->attributes()
        );
    }

    // 重写获取验证数据方法
    public function validated()
    {
        $rules = $this->container->call([$this, 'combine']);

        return $this->only(collect($rules)->keys()->map(function ($rule) {
            return explode('.', $rule)[0];
        })->unique()->toArray());
    }

    // ...
}
```

```
class FormRequestGatherTest
{
    // 展现构筑规则方法名
    protected $showSource = true;

    // 展现当前请求验证的所有规则
    protected $showRule = true;

    // 该规则任何时候都生效, 但是优先级最低, 可被其它规则重写
    public function rules()
    {
        return [
            'idcode' => 'identitys',
            'phone'  => 'phone'
        ];
    }

    // 构筑规则获得如下方法, 该规则仅 get 请求生效
    public function rulesGet()
    {
        return [
            'phone' => 'bail|required|phone',
            'password' => 'bail|required|password:c',
        ];
    }

    // 构筑规则获得如下方法, 该规则仅 admin/system/role 路径请求生效
    public function rulespathAdminSystemRole()
    {
        return [
            //
        ];
    }

    // 构筑规则获得如下方法, 该规则仅路由名 role 请求生效
    public function rulesrouteRole()
    {
        return [
            //
        ];
    }
}
```

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

Total

3

Last Release

2714d ago

### Community

Maintainers

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

---

Top Contributors

[![caixingyue](https://avatars.githubusercontent.com/u/39073687?v=4)](https://github.com/caixingyue "caixingyue (11 commits)")

### Embed Badge

![Health badge](/badges/starrysea-validate/health.svg)

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

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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