PHP code example of yemenifree / laravel-validation

1. Go to this page and download the library: Download yemenifree/laravel-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

yemenifree / laravel-validation example snippets


use Yemenifree\Validation\Traits\HasValidator;

class SomeController
{
    use HasValidator;
    //
}

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

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

use Yemenifree\Validation\Traits\HasValidator;

class SomeController
{
    use HasValidator;
    
    /**
     * Register User
     *
     * @return array
     */
    public function register()
    {
        $isValid = $this->valid(
        [
            'username' => 'salah',
            'password' => 'test'
        ]
        , [
            'username' => 'n
     */
    public function InValidCallback(array $errors)
    {
        // do whatevet you want with errors.
        
        return false;
    }
}

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' => '

use Yemenifree\Validation\Traits\HasValidator;

class SomeController
{
    use HasValidator;

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