2017 © Pedro Peláez
 

library validators

Laravel Validators

image

lakshmaji/validators

Laravel Validators

  • Sunday, June 3, 2018
  • by lakshmaji
  • Repository
  • 0 Watchers
  • 0 Stars
  • 62 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 48 % Grown

The README.md

Validators

What it is

  • Validator helpers for Laravel Validation.

Version

1.0.1, (*1)

Sample

Image, (*2)

Compatibility

Laravel version Validators version
5.5 1.0.1
5.4 <= ? (not sure)

Installation

  • This package is available through composer installation
    composer require lakshmaji/validators
  • Try updating the application with composer (autloading class namespaces but not mandatory :wink: )
  composer dump-autoload

Configurations

  • Publish the configuration file.
    php artisan vendor:publish
  • The configuration file will be published to your application config directory with the name * validators.php*.
  • Configure the required validator namespaces and validator class paths., (*3)

  • An example configuration file (validators.php)., (*4)

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Validator namespace
    |--------------------------------------------------------------------------
    |
    | The namespace for the validator classes.
    |
     */
    'validator_namespace' => 'App\Validators',

    /*
    |--------------------------------------------------------------------------
    | Validator path
    |--------------------------------------------------------------------------
    |
    | The path to the validators folder.
    |
     */
    'validator_path' => 'app' . DIRECTORY_SEPARATOR . 'MyValidators' . DIRECTORY_SEPARATOR . 'MyRules',

];

Generating Validator

  • Issue the following command in terminal
php artisan make:validator CreateVehicle
  • This will generate the following class and located the path configured in validators.php
<?php 

namespace App\MyValidators\MyRules;

use Lakshmaji\Validators\Laravel\LaravelValidator;
use Lakshmaji\Validators\Contracts\ValidableInterface;


/**
 * Class CreateVehicleValidator
 * @package App\MyValidators\MyRules
 */
class CreateVehicleValidator extends LaravelValidator implements ValidableInterface
{
    /**
     * @var array
     */
    protected $rules = [
        'name' => 'required',
        'model' => 'required'
    ];

    /**
     * @var array
     */
    protected $messages = [
        'model.required' => 'Please specify the model number',
    ];
}
// end of CreateVehicleValidator class

Using it in action

<?php
namespace App\Http\Controllers\Cars;

use App\MyValidators\MyRules\CreateVehicleValidator;


protected $request;
protected $validator;

public function  __construct(Request $request, CreateVehicleValidator $validator) {
  $this->validator = $validator;
  $this->request = $request;
}

public function store() {
  $payload = $this->request->all();

  // validate here
  if($this->validator->with($payload)->passes()) {
    // validation succedded
  } else {
    $errors = $this->validator->formatErrorMessages();
  }
}

MISCELLANEOUS

  • After installing package you find the artisan commands in your project, (*5)

    php artisan list
    
  • OR, (*6)

php artisan help make:validator

Thanks to

[@parthshukla] (https://github.com/parthshukla), (*7)

LICENSE

MIT, (*8)

The Versions

03/06 2018

dev-master

9999999-dev

Laravel Validators

  Sources   Download

MIT

by Avatar lakshmaji

laravel composer validator

03/06 2018

1.0.2

1.0.2.0

Laravel Validators

  Sources   Download

MIT

by Avatar lakshmaji

laravel composer validator

28/01 2018

1.0.1

1.0.1.0

Laravel Validators

  Sources   Download

MIT

by Avatar lakshmaji

laravel composer validator

28/01 2018

1.0.0

1.0.0.0

Laravel Validators

  Sources   Download

MIT

by Avatar lakshmaji

laravel composer validator