bekusc/laravel-auto-validation 问题修复 & 功能扩展

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

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

bekusc/laravel-auto-validation

最新稳定版本:1.0.1

Composer 安装命令:

composer require bekusc/laravel-auto-validation

包简介

README 文档

README

This package will allow you to remove all manual validations from your controllers.

Installation

Simply go to your project directory where the composer.json file is located and type in your terminal:

composer require bekusc/laravel-auto-validation

Add the service provider to your providers array in config/app.php:

'providers' => [
    // ...
    Bekusc\Validation\AutoValidationProvider::class,
],

Add the trait to your base controller App\Http\Controllers\Controller:

use Bekusc\Validation\Traits\AutoValidation;

class Controller extends BaseController
{
    use AutoValidation;
}

Publish config:

php artisan vendor:publish --provider="Bekusc\Validation\AutoValidationProvider"

Update config file with your validation rules in:

config/validation.php

Example

config/validation.php file:

use Illuminate\Validation\Rule;

$rules = [
    'UserController' => [
        'register' => [
            'name'     => 'required|max:255',
            'email'    => ['required', 'email', 'max:255', Rule::unique('users')->where('status', 1)],
            'password' => 'required|min:6|confirmed',
            'gender'   => 'required|in:male,female',
            'birthday' => 'required|date_format:Y-n-j',
        ],
        'update' => function ($request) {
            return [
                'name'     => 'required|max:255',
                'email'    => 'required|email|max:255|unique:users,email,'.$request->user()->id,
                'gender'   => 'required|in:male,female',
                'birthday' => 'required|date_format:Y-n-j',
            ];
        },
    ],
];

return ['rules' => $rules];

UserController.php file:

class UserController extends Controller
{
    public function register(Request $request)
    {
        // The incoming request is valid...
        User::create($request->all());
    }

    public function update(Request $request)
    {
        // The incoming request is valid...
        $request->user()->update($request->all());
    }
}

Note

If validation fails, a redirect response will be generated to send the user back to their previous location. The errors will also be flashed to the session so they are available for display. If the request was an AJAX request, a HTTP response with a 422 status code will be returned to the user including a JSON representation of the validation errors.

统计信息

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

GitHub 信息

  • Stars: 61
  • Watchers: 1
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-05-02

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固