Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bashleigh/laravalidator
Laravel validation service provider to allow creation of validation classes
https://github.com/bashleigh/laravalidator
custom laravel laravel54 php71 validation
Last synced: about 1 month ago
JSON representation
Laravel validation service provider to allow creation of validation classes
- Host: GitHub
- URL: https://github.com/bashleigh/laravalidator
- Owner: bashleigh
- Created: 2017-06-25T17:34:42.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-25T19:02:50.000Z (over 7 years ago)
- Last Synced: 2024-09-28T19:03:55.111Z (3 months ago)
- Topics: custom, laravel, laravel54, php71, validation
- Language: PHP
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Installation
Add the service provider to your providers array in `config/app.php`
```php
'providers' => [
...
ChickenTikkaMasala\LaraValidator\ValidatorServiceProvider::class,
...
];
```Now create a class that extends AbstractValidator in `App\Validators`;
```php
'custom',
];```
### Validating parameters
I've added a small exception throwing function that 'validates' the parameters passed.
```php
public function execute($attribute, $value, array $parameters, $validator) : boolean {
$this->validateParameters($parameters, [
0 => 'table name',
]);
}
```Now if we did this with our custom validator
```php
public $rules = [
'field' => 'custom',
];```
We would get an exception```php
RequiredParameterException in AbstractValidator.php line 40:
The parameter "table name" is required.
```### Make function
You can use the `make:validator` command to create a new validator class
```bash
php artisan make:validator CustomValidator
```And that's pretty much it! It's the simple things ;)