Package Data | |
---|---|
Maintainer Username: | chickenTikkaMasala |
Maintainer Contact: | ashleighsimonelli@gmail.com (ashleigh simonelli) |
Package Create Date: | 2017-06-25 |
Package Last Update: | 2017-06-25 |
Language: | PHP |
License: | Unknown |
Last Refreshed: | 2024-11-23 03:04:28 |
Package Statistics | |
---|---|
Total Downloads: | 14 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 2 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Add the service provider to your providers array in config/app.php
'providers' => [
...
ChickenTikkaMasala\LaraValidator\ValidatorServiceProvider::class,
...
];
Now create a class that extends AbstractValidator in App\Validators
;
<?php
namespace App\Validators;
use \ChickenTikkaMasala\LaraValidator\Validators\AbstractValidator;
class CustomValidator extends AbstractValidator
{
public $name = 'custom';
public function execute($attribute, $value, array $parameters, $validator) : boolean {
return true;
}
public function message($message, $attribute, $rule, array $parameters) : string {
return 'your custom validation failed';
}
}
Now use your custom validation like
public $rules = [
'field' => 'custom',
];
I've added a small exception throwing function that 'validates' the parameters passed.
public function execute($attribute, $value, array $parameters, $validator) : boolean {
$this->validateParameters($parameters, [
0 => 'table name',
]);
}
Now if we did this with our custom validator
public $rules = [
'field' => 'custom',
];
We would get an exception
RequiredParameterException in AbstractValidator.php line 40:
The parameter "table name" is required.
You can use the make:validator
command to create a new validator class
php artisan make:validator CustomValidator
And that's pretty much it! It's the simple things ;)