2017 © Pedro Peláez
 

project laravalidator

Validation service provider.

image

chickentikkamasala/laravalidator

Validation service provider.

  • Sunday, June 25, 2017
  • by chickenTikkaMasala
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 0 % Grown

The README.md

Installation

Add the service provider to your providers array in config/app.php, (*1)

'providers' => [
    ...
    ChickenTikkaMasala\LaraValidator\ValidatorServiceProvider::class,
    ...
 ];

Now create a class that extends AbstractValidator in App\Validators;, (*2)

<?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, (*3)

public $rules = [
    'field' => 'custom',
];

Validating parameters

I've added a small exception throwing function that 'validates' the parameters passed., (*4)

public function execute($attribute, $value, array $parameters, $validator) : boolean {
    $this->validateParameters($parameters, [
        0 => 'table name',
    ]);
}

Now if we did this with our custom validator, (*5)

public $rules = [
    'field' => 'custom',
];

We would get an exception, (*6)

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, (*7)

php artisan make:validator CustomValidator

And that's pretty much it! It's the simple things ;), (*8)

The Versions

25/06 2017

dev-master

9999999-dev

Validation service provider.

  Sources   Download

The Requires

  • php >=7.0

 

by ashleigh simonelli

laravel validator

25/06 2017

0.2

0.2.0.0

Validation service provider.

  Sources   Download

The Requires

  • php >=7.0

 

by ashleigh simonelli

laravel validator

25/06 2017

0.1

0.1.0.0

Validation service provider.

  Sources   Download

The Requires

  • php >=7.0

 

by ashleigh simonelli

laravel validator