PHPackages                             swoft-laravel/validation - 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. swoft-laravel/validation

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

swoft-laravel/validation
========================

laravel validation in swoft

v1.0.3(6y ago)1105MITPHP

Since May 21Pushed 6y agoCompare

[ Source](https://github.com/RiceWong/swoft-laravel-validation)[ Packagist](https://packagist.org/packages/swoft-laravel/validation)[ RSS](/packages/swoft-laravel-validation/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

swoft-laravel-validation
========================

[](#swoft-laravel-validation)

集成 laravel校验类至 swoft

php &gt;7.2, swoft &gt; v1.9 (暂不支持v2.x)

技术细节
----

[](#技术细节)

1. 技术目标:
    - 独立使用 laravel validation组件，文档和使用方式参考 laravel 社区文档
    - 在尽可能精简代码的前提下，尽可能迁移 laravel validation的功能：Validation, 多语言模板支持，通用校验方法
2. 实现:
    - 参照laravel validation的加载依赖，加载validation所需要的Validator Factory, Translator组件
    - Validator 类行为与laravel validator facade一致

安装
--

[](#安装)

在composer.json require 中添加如依赖

```
...
    "require": {
        ...
        "swoft-laravel/validation": "^1.0.3",
        ...
    }
....
```

更新依赖

```
# 更新所有依赖
composer update
# 或者只更新生产环境依赖
composer update --no-dev
```

在根目录下新建文件结构:

```
./resources/
└── lang
    ├── en
    └── zh
        ├── message.php

```

使用
--

[](#使用)

详细用法可参考laravel官方文档:

- [英文文档](https://laravel.com/docs/5.8/validation)
- [中文文档](https://learnku.com/docs/laravel/5.7/validation/3899)

```
use SwoftLaravel\Validation\Validator;
class Controller{
    public function test($request) {
        $data = $reqquest->post();
        $rules = [
            'mobile' => 'required|mobile',
            'email' => 'required|email'
        ];
        $errmap = [
            'mobile.required' => '手机号不能为空',
            'mobile.mobile' => '手机号格式不正确',
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确'
        ];
        $validator = Validator::make($data, $rules, $errmap);
        $error = null;
        if ($validator->fails()) {
            $validateErrors = $validator->messages();
            $error = [];
            foreach ($validateErrors->keys() as $field) {
                $msg = $validateErrors->get($field);
                $error[$field] = $msg[0];
            }
        }
    }
}
```

使用通用校验类

```
use SwoftLaravel\Validation\Traits\TraitValidate;
class MockController{
    use TraitValidate;
    public function test($request) {
        $data = $reqquest->post();
        $rules = [
            'mobile' => 'required|mobile',
            'email' => 'required|email'
        ];
        $errmap = [
            'mobile.required' => '手机号不能为空',
            'mobile.mobile' => '手机号格式不正确',
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确'
        ];
        $errors = $this->validateError($data, $rules, $errmap);
        if ($errors !== null){
            return success_result($errors);
        }
    }
}
```

模板文件的使用 详细用法可参考官方文档：

- [英文文档](https://laravel.com/docs/5.7/localization)
- [中文文档](https://learnku.com/docs/laravel/5.7/localization/2266)

```
// 新增模板文件./resources/lang/zh/message.php
return [
    'system_busy'   => '系统繁忙, 请重试',
    'mobile'        => [
        'required'     => '请输入11位手机号',
        'invalid'      => '请输入11位手机号',
        'registered'   => '该账号已注册',
        'unregistered' => '该账号未注册'
    ],
    'vcode' => '你的注册码为
];
// 使用模板
$message = translator('message.systembusy');
```

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity63

Established project with proven stability

 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

4

Last Release

2547d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/75e47d85eca2ecd5ac032a7ec467e3811a2070600b817adc28c444a2507476b0?d=identicon)[rickywong](/maintainers/rickywong)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/swoft-laravel-validation/health.svg)

```
[![Health](https://phpackages.com/badges/swoft-laravel-validation/health.svg)](https://phpackages.com/packages/swoft-laravel-validation)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[sunspikes/clamav-validator

Custom Laravel 5 anti-virus validator for file uploads.

3651.8M3](/packages/sunspikes-clamav-validator)

PHPackages © 2026

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