Package Data | |
---|---|
Maintainer Username: | Sukohi |
Maintainer Contact: | capilano.sukohi@gmail.com (Sukohi) |
Package Create Date: | 2015-10-29 |
Package Last Update: | 2015-10-29 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:11:58 |
Package Statistics | |
---|---|
Total Downloads: | 15 |
Monthly Downloads: | 1 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
A Laravel package to manage validation for array values.
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
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() !!}
This package is licensed under the MIT License.
Copyright 2015 Sukohi Kuhoh