seffeng / laravel-rules by seffeng

PHP laravel extension rules
3,408
0
2
Package Data
Maintainer Username: seffeng
Maintainer Contact: save.zxf@gmail.com (seffeng)
Package Create Date: 2020-05-21
Package Last Update: 2023-03-10
Language: PHP
License: MIT
Last Refreshed: 2024-12-22 15:01:16
Package Statistics
Total Downloads: 3,408
Monthly Downloads: 21
Daily Downloads: 0
Total Stars: 0
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Laravel Rules

安装

# 安装
$ composer require seffeng/laravel-rules

目录说明

├─src
│  └─Rules                  验证规则
│       Password.php            密码
│       Phone.php               手机号

示例

/**
 * TestRequest.php
 * 表单验证示例
 */
namespace App\Http\Requests;

use Seffeng\LaravelRules\Rules\Password;
use Seffeng\LaravelRules\Rules\Phone;

class TestRequest
{
    protected $fillable = ['phone', 'password'];

    public function rules()
    {
        return [
            'phone' => [
                'required',
                new Phone()
            ],
            'password' => [
                'required',
                new Password()
            ],
        ];
    }

    public function messages()
    {
        return [
            'required' => ':attribute不能为空!'
        ];
    }

    public function attributes()
    {
        return [
            'phone' => '手机号',
            'password' => '密码',
        ];
    }
}

备注