2017 © Pedro PelĂĄez
 

library validation

Illuminate validation outside Laravel

image

xaamin/validation

Illuminate validation outside Laravel

  • Thursday, December 29, 2016
  • by xaamin
  • Repository
  • 1 Watchers
  • 1 Stars
  • 220 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 6 % Grown

The README.md

Illuminate Validator Outside Laravel

Installation

composer require xaamin/$validator, (*1)

Usage

use Xaamin\Validator\Validator;

$validator = new Validator;
Database presence verifier

Using the Illuminate Database Capsule set the database connection instance:, (*2)

$db = $capsule->getDatabaseManager();

$validator->setConnection($db);
Providing a custom translator

To provide a custom translator pass an instance of Illuminate\Container\Container with the translator bound to translator., (*3)

The translator must implement Symfony\Component\Translation\TranslatorInterface., (*4)

$container = new Illuminate\Container\Container;

$container['translator'] = new CustomTranslator();

$validator = new Validator($container);
Creating validators
$validator = Validator::make(
    [
        'name' => 'John',
        'last_name' => 'Doe'
    ],
    [
        'name' => ['required', 'min:3'],
        'last_name' => ['required', 'min:3']
    ]
);
Working with error messages

After calling the errors method on a Validator instance, you will receive an Illuminate\Support\MessageBag instance, which has a variety of convenient methods for working with error messages., (*5)

Retrieving The First Error Message For A Field, (*6)

To retrieve the first error message for a given field, use the first method:, (*7)

$messages = $validator->errors();

echo $messages->first('email');
Retrieving all error messages for a field

If you wish to simply retrieve an array of all of the messages for a given field, use the get method:, (*8)

foreach ($messages->get('email') as $message) {
    //
}
Retrieving all error messages for all fields

To retrieve an array of all messages for all fields, use the all method:, (*9)

foreach ($messages->all() as $message) {
    //
}
Determining if messages exist for a field
if ($messages->has('email')) {
    //
}
Retrieving an error message with a format
echo $messages->first('email', '

:message, (*10)

'); Retrieving All Error Messages With A Format foreach ($messages->all('<li>:message</li>') as $message) { // }

See all avalilable rules and methods at Laravel validations., (*11)

The Versions

29/12 2016

dev-master

9999999-dev

Illuminate validation outside Laravel

  Sources   Download

The Requires

 

29/12 2016

v1.0.3

1.0.3.0

Illuminate validation outside Laravel

  Sources   Download

The Requires

 

29/12 2016

v1.0.2

1.0.2.0

Illuminate validation outside Laravel

  Sources   Download

The Requires

 

29/12 2016

v1.0.1

1.0.1.0

Illuminate validation outside Laravel

  Sources   Download

The Requires

 

29/12 2016

v1.0

1.0.0.0

Illuminate validation outside Laravel

  Sources   Download

The Requires