2017 © Pedro Peláez
 

library array-validator

A Laravel package to manage validation for array values.

image

sukohi/array-validator

A Laravel package to manage validation for array values.

  • Thursday, October 29, 2015
  • by Sukohi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 9 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

ArrayValidator

A Laravel package to manage validation for array values., (*1)

Installation

Add this package name in composer.json, (*2)

"require": {
  "sukohi/array-validator": "1.*"
}

Execute composer command., (*3)

composer update

Usage

Make your own Request using the following command., (*4)

php artisan make:request *****Request
  • see here for the details

Set ArrayValidator the Request class like this., (*5)

<?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., (*6)

public function rules()
{
    return [
        'emails' => 'required|email'
    ];
}

Set Attribute, (*7)

You also can set attribute names as usual.
{key} will be replaced with array key like 0, 1, 2, key., (*8)

public function attributes() {

    return [
        'titles' => 'Title - {key}'
    ];

}

Get Error Message, (*9)

(in Blade), (*10)

{{ $errors->first('titles.0') }}
{{ $errors->first('titles.1') }}
{{ $errors->first('titles.2') }}
{{ $errors->first('titles.key') }}

Note, (*11)

If you use Collective package, you need to set input names like this., (*12)

{!! Form::text('titles[0]') !!}<br>
{!! Form::text('titles[1]') !!}<br>
{!! Form::text('titles[2]') !!}<br>
{!! Form::text('titles[key]') !!}

HTML Example, (*13)

<!-- 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., (*14)

Copyright 2015 Sukohi Kuhoh, (*15)

The Versions

29/10 2015

1.0.x-dev

1.0.9999999.9999999-dev

A Laravel package to manage validation for array values.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

29/10 2015

dev-master

9999999-dev

A Laravel package to manage validation for array values.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

29/10 2015

1.0.2

1.0.2.0

A Laravel package to manage validation for array values.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

29/10 2015

1.0.1

1.0.1.0

A Laravel package to manage validation for array values.

  Sources   Download

MIT

The Requires

 

by Avatar Sukohi

29/10 2015

1.0.0

1.0.0.0

A Laravel package to manage validation for array values.

  Sources   Download

The Requires

 

by Avatar Sukohi