Package Data | |
---|---|
Maintainer Username: | xaamin |
Maintainer Contact: | xaamin@outlook.com (Benjamín Martínez Mateos) |
Package Create Date: | 2016-12-29 |
Package Last Update: | 2016-12-29 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-16 15:02:30 |
Package Statistics | |
---|---|
Total Downloads: | 475 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 2 |
Total Open Issues: | 0 |
composer require xaamin/$validator
use Xaamin\Validator\Validator;
$validator = new Validator;
Using the Illuminate Database Capsule set the database connection instance:
$db = $capsule->getDatabaseManager();
$validator->setConnection($db);
To provide a custom translator pass an instance of Illuminate\Container\Container
with the translator bound to translator
.
The translator must implement Symfony\Component\Translation\TranslatorInterface
.
$container = new Illuminate\Container\Container;
$container['translator'] = new CustomTranslator();
$validator = new Validator($container);
$validator = Validator::make(
[
'name' => 'John',
'last_name' => 'Doe'
],
[
'name' => ['required', 'min:3'],
'last_name' => ['required', 'min:3']
]
);
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.
Retrieving The First Error Message For A Field
To retrieve the first error message for a given field, use the first method:
$messages = $validator->errors();
echo $messages->first('email');
If you wish to simply retrieve an array of all of the messages for a given field, use the get method:
foreach ($messages->get('email') as $message) {
//
}
To retrieve an array of all messages for all fields, use the all method:
foreach ($messages->all() as $message) {
//
}
if ($messages->has('email')) {
//
}
echo $messages->first('email', '<p>:message</p>');
Retrieving All Error Messages With A Format
foreach ($messages->all('<li>:message</li>') as $message) {
//
}
See all avalilable rules and methods at Laravel validations.