2017 © Pedro Peláez
 

library validator-loader-laravel

Service provider to load Laravel validator definitions from files or directories

image

frbit/validator-loader-laravel

Service provider to load Laravel validator definitions from files or directories

  • Monday, August 18, 2014
  • by ukautz
  • Repository
  • 3 Watchers
  • 4 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 0 % Grown

The README.md

Service provider for Validator Loader

Allows you to source your validation rules out into files (.json, .yml, .php) or structure them in directories. Comes with a simple inheritance feature and variables to reduce writing the same regex (or whatnot) over and over again (see the Validator Validator Loader package)., (*1)

Installation

``` bash $ php composer.phar require "frbit/validator-loader-laravel:*", (*2)


Now add the service provider and the facade (if you want) to `app/config/app.php` ``` php <?php return array( # ... 'providers' => array( # ... 'Frbit\ValidatorLoader\Laravel\ValidatorLoaderServiceProvider', ), # ... 'aliases' => array( # ... 'ValidatorLoader' => 'Frbit\ValidatorLoader\Laravel\Facade\ValidatorLoader' ) )

Usage

This package provides a facade and registeres with the IoC Container., (*3)

Please see the readme of the Validator Loader package for examples for validation rules., (*4)

Using the facade

Somewhere in your model or controller:, (*5)

``` php <?php, (*6)

// get the input for validation $input = Input::all();, (*7)

// this returns just the same as Laravel's \Validator::make($input, $rules) would $validator = \ValidatorLoader::get("my-form", $input); if ($validator->fails()) { # .. ), (*8)


### Using the IoC Somewhere in your model or controller: ``` php <?php // get the input for validation $input = Input::all(); // this returns just the same as Laravel's \Validator::make($input, $rules) would $loader = \App::make("validator-loader"); $validator = $loader->get("my-form", $input); if ($validator->fails()) { # .. )

Configuration

First publish the configuration, (*9)

``` bash $ php artisan config:publish frbit/validator-loader-laravel, (*10)


You can find the config in `app/config/packages/frbit/validator-loader-laravel` ### Rules in file Having all validation rules in a single file. Set `source` to `file` and write your validation rules in `sources.file`: ``` php <?php return array( 'source' => 'file', 'sources' => array( // relative paths are considered realtive to app folder 'file' => 'path/to/file' ) );

Rules in directory

When extensive validation rules are required or a neat structure is preferred. Set source to directory and write your validation rules in sources.directory:, (*11)

``` php <?php, (*12)

return array( 'source' => 'directory', 'sources' => array(, (*13)

    // relative paths are considered realtive to app folder
    'directory' => 'path/to/directory'
)

);, (*14)


### Rules in array For testing, I suppose. Set `source` to `array` and write your validation rules in `sources.array`: ``` php <?php return array( 'source' => 'array', 'sources' => array( 'array' => array( # .. ) ) );

Caching

Especially for directory sources, loading validation rules can lead to increased disk i/o on each request which reduces performances. Caching allows you to mitigate this., (*15)

``` php <?php, (*16)

return array( // time in minutes -> set to 0 to disable caching 'cache' => 123,, (*17)

// key name under which cache is stored
'cache-key' => 'some-key-name',

); ```, (*18)

The Versions

18/08 2014

dev-master

9999999-dev

Service provider to load Laravel validator definitions from files or directories

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation service provider

18/08 2014

0.1.3

0.1.3.0

Service provider to load Laravel validator definitions from files or directories

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation service provider

18/08 2014

0.1.2

0.1.2.0

Service provider to load Laravel validator definitions from files or directories

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel validator validation service provider

14/03 2014