2017 © Pedro Peláez
 

library laravel-validation

Use laravel validation standalone support translate.

image

yemenifree/laravel-validation

Use laravel validation standalone support translate.

  • Monday, November 27, 2017
  • by salahalkhwlani
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

PHP Laravel Validation.

Software License Build Status ![Quality Score][ico-code-quality], (*1)

A tiny package to use laravel validation outside laravel with support translate error message. this package is extend for rakit/validation so read it's document for more information., (*2)

Features

  • Init validation easy with trait.
  • Support Multi lang for error messages.
  • More come soon.

Requirements & Installation

Requires PHP 7.0+, (*3)

Via Composer, (*4)

``` bash $ composer require yemenifree/laravel-validation, (*5)


## Getting Started To init validation on class add `HasValidator` trait. ```php use Yemenifree\Validation\Traits\HasValidator; class SomeController { use HasValidator; // }

Then to valid some data you can pass array for data & rules and others options., (*6)

    $this->valid(array $data, array $rules, array $messages = [], array $aliases = [])

For example, (*7)

/**
 * Register User
 *
 * @return array
 */
public function register()
{
    $isValid = $this->valid(
    [
        'username' => 'salah',
            'password' => 'test'
    ]
    , [
        'username' => 'required',
        'password' => 'required',
    ]);

    if(!$isValid){
        // data not valid.
    }

    // every thing right.
}

If you have same response for all form in controller you can handler validation error once by create InValidCallback in class., (*8)

use Yemenifree\Validation\Traits\HasValidator;

class SomeController
{
    use HasValidator;

    /**
     * Register User
     *
     * @return array
     */
    public function register()
    {
        $isValid = $this->valid(
        [
            'username' => 'salah',
            'password' => 'test'
        ]
        , [
            'username' => 'required',
            'password' => 'required',
        ]);

        // if data not valid will excute `InValidCallback` in this class.
        if(!$isValid)
        {
            return;
        }

        // every thing right.
    }

    /**
     * In valid function.
     *
     * @param array $errors
     *
     * @throws InvalidArgumentException
     */
    public function InValidCallback(array $errors)
    {
        // do whatevet you want with errors.

        return false;
    }
}

You can use custom translate file for validation errors., (*9)

use Yemenifree\Validation\Traits\HasValidator;

class SomeController
{
    use HasValidator;

    public function __construct()
    {
        $this->setValidatorLocal(
// file name wihout .php
        'ar',
        // path of translate
        'translate/path'
        );
    }

    /**
     * Register User
     *
     * @return array
     */
    public function register()
    {
        $isValid = $this->valid(
        [
            'username' => 'salah',
            'password' => 'test'
        ]
        , [
            'username' => 'required',
            'password' => 'required',
        ]);

         if(!$isValid)
        {
            // message errors.
            $errors = $this->getValidErrors();
        }

        // every thing right.
    }
}

translate files must return array of messages. see src/lang/ar.php for example., (*10)

To access to all method of Validator use getValidator() method., (*11)

use Yemenifree\Validation\Traits\HasValidator;

class SomeController
{
    use HasValidator;

    public function __construct()
    {
        // add custom rule.
        $this->getValidator()->addValidator('simple', new SimpleRule());
    }
}

For more information about rules check rakit/validation, (*12)

Change log

Please see CHANGELOG for more information on what has changed recently., (*13)

Contributing

Please see CONTRIBUTING for details., (*14)

Security

If you discover any security related issues, please email yemenifree@yandex.com instead of using the issue tracker., (*15)

Credits

License

The MIT License (MIT). Please see License File for more information., (*16)

The Versions

27/11 2017

dev-master

9999999-dev

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

27/11 2017

0.0.7

0.0.7.0

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

27/11 2017

0.0.8

0.0.8.0

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

27/11 2017

0.0.6

0.0.6.0

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

27/11 2017

0.0.5

0.0.5.0

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

27/11 2017

0.0.4

0.0.4.0

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

27/11 2017

0.0.3

0.0.3.0

Use laravel validation standalone support translate.

  Sources   Download

The Requires

 

23/11 2017

0.0.2

0.0.2.0

use laravel validation via wordpress

  Sources   Download

The Requires

 

23/11 2017

0.0.1

0.0.1.0

use laravel validation via wordpress

  Sources   Download

The Requires