cals/validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

cals/validator

Composer 安装命令:

composer require cals/validator

包简介

A simple encapsulation of Illuminate\Contracts\Validation\Factory in Laravel.

README 文档

README

Build Status Scrutinizer Code Quality Code Coverage Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Validator is designed for Laravel when use ajax. Validator is a simple encapsulation of Illuminate\Contracts\Validation\Factory in Laravel, which excepted validating data easier.

Install

You can simply install Validator use composer.

composer require cals/validator

And then add the Cals\Validator\ValidatorServiceProvider::class to your config/app.php providers array.

Cals\Validator\ValidatorServiceProvider::class

If you use Laravel 5.5 and after, you don't need do it cause laravel will auto load the provider.

Configuration

You have to publish the config using this command:

php artisan vendor:publish --tag="validator"

You should put your rules and messages in it.

Usage

Validator provides a simple way to validate data, you can simply use it anywhere you want.

validate(array $values = [], $resource, array $messages = [], $sometimes = false)

$values is the data you wish to validate, $resource is one of your key in rules which contained in validator.php. And you can set messages while validating fails to return by using $message.When $sometimes was true, rules in sometimes would be used.

When validate failed, Validator will send a json response automatically.The returned data is like this.

{
    "errors": {
        "username": [
            "用户名不能为空"
        ],
        "password": [
            "密码不能是字母、数字、破折号和下划线之外的其他字符",
            "密码必须在 6 到 18 位之间"
        ]
    }
}

Example

Validator suggest using like this.

<?php

namespace App\Http\Controllers;

use Cals\Validator\AjaxValidator;
use Illuminate\Http\Request;

class ExampleController extends Controller
{
    private $validator;
    
    public function __construct(AjaxValidator $validator)
    {
        $this->validator = $validator;
    }

    public function index(Request $request)
    {
        $values = $request->all();
        $this->validator->validate($values,'user');
    }
}

License

The Validator is open-sourced library licensed under the MIT license.

统计信息

  • 总下载量: 54
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-12-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固