Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

sandyandi/laravel-validation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Extended Laravel Validation

This is a slightly modified version of KaneCohen's laravel-validation library that focuses on displaying individual error messages and utilizing Laravel's validation language file.

Installation

  1. Add the following to your require composer.json file:
"cohensive/validation": "dev-master",
"sandyandi/validation": "1.0.*@dev"
  1. Run composer update and wait for it to download and install.
  2. Open app/config/app.php, comment out Laravel's default validation service provider: 'Illuminate\Validation\ValidationServiceProvider', and add this library's service provider: 'Sandyandi\Validation\ValidationServiceProvider',

Usage

The core usage documentation is found here: laravel-validation

The modification made to this library are the following:

  • You can use indexes in your validation rules array, eg:
$rules = array(
     'income_sources:0:employer_name' => 'required',
     'income_sources:1:employer_name' => 'required'
);

If the validation fails, you can know which employer_name failed the validation as it has an index and you can show its individual error message using something like:

$errors->has('income_sources:0:employer_name');

...or

$errors->first('income_sources:0:employer_name');

Tip: Use a loop to create those indexes.

  • You can use the validation language file (app/lang/en/validation.php) like the following:
'custom' => array(
     'income_sources:employer_name' => 'Please let us know who your employer is.'
)

...and

'attributes' => array(
     'income_sources:employer_name' => 'employer name.'
)

And those language keys will refer to validation rule keys like 'income_sources:0:employer_name', 'income_sources:1:employer_name' (whatever index you specify) or 'income_sources:*:employer_name'

About

Modified version of KaneCohen's Laravel 4 Validator.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages