sukohi/array-validator
最新稳定版本:1.0.2
Composer 安装命令:
composer require sukohi/array-validator
包简介
A Laravel package to manage validation for array values.
README 文档
README
A Laravel package to manage validation for array values.
Installation
Add this package name in composer.json
"require": {
"sukohi/array-validator": "1.*"
}
Execute composer command.
composer update
#Usage
Make your own Request using the following command.
php artisan make:request *****Request
- see here for the details
Set ArrayValidator the Request class like this.
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Sukohi\ArrayValidator\ArrayValidatorTrait;
class YourRequest extends Request
{
use ArrayValidatorTrait;
// Something..
}
Now your Request class can manage array validation. So add your validation rules there as usual.
public function rules()
{
return [
'emails' => 'required|email'
];
}
Set Attribute
You also can set attribute names as usual.
{key} will be replaced with array key like 0, 1, 2, key.
public function attributes() {
return [
'titles' => 'Title - {key}'
];
}
Get Error Message
(in Blade)
{{ $errors->first('titles.0') }}
{{ $errors->first('titles.1') }}
{{ $errors->first('titles.2') }}
{{ $errors->first('titles.key') }}
Note
If you use Collective package, you need to set input names like this.
{!! Form::text('titles[0]') !!}<br>
{!! Form::text('titles[1]') !!}<br>
{!! Form::text('titles[2]') !!}<br>
{!! Form::text('titles[key]') !!}
HTML Example
<!-- Errors -->
@if($errors->first('titles.0'))
{{ $errors->first('titles.0') }}<br>
@endif
@if($errors->first('titles.1'))
{{ $errors->first('titles.1') }}<br>
@endif
@if($errors->first('titles.2'))
{{ $errors->first('titles.2') }}<br>
@endif
@if($errors->first('titles.key'))
{{ $errors->first('titles.key') }}<br>
@endif
<!-- Form -->
{!! Form::open(['route' => 'YOUR-ROUTE']) !!}
{!! Form::text('titles[0]') !!}<br>
{!! Form::text('titles[1]') !!}<br>
{!! Form::text('titles[2]') !!}<br>
{!! Form::text('titles[key]') !!}
<button type="submit">Submit</button>
{!! Form::close() !!}
License
This package is licensed under the MIT License.
Copyright 2015 Sukohi Kuhoh
统计信息
- 总下载量: 16
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-29