PHP code example of two-bros / validation-service

1. Go to this page and download the library: Download two-bros/validation-service 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/ */

    

two-bros / validation-service example snippets


    'providers' => [
        ...
        TwoBros\ValidationService\Providers\ValidationServiceProvider::class,
    ];

    return [
        'passwordStrength' => 'User@passwordStrength'
    ];

    use TwoBros\ValidationService\Services\Validation\LaravelValidator;
    
    class ModelCreateValidator extends LaravelValidator
    {
        protected $rules = [
            'name' => '

    $modelValidator = new ModelCreateValidator($this->app['validator']);
    
    if ($modelValidator->with($inputArray)
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();
        
        // Do some stuff for failing
    }

    $messages = [
        'dator = new ModelCreateValidator($this->app['validator']);
    
    if ($modelValidator->with($inputArray, $messages)
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();
        
        // Do some stuff for failing
    }            

    $messages = [
        'dator = new ModelCreateValidator($this->app['validator']);
    
    if ($modelValidator->with($inputArray)
                       ->withMessages($messages)
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();
        
        // Do some stuff for failing
    }

    use TwoBros\ValidationService\Services\Validation\LaravelValidator;
    
    class ModelCreateValidator extends LaravelValidator
    {
        protected $rules = [
            'name' => 'd|max:100|unique:users,email,' . $this->uniqueIds[ 'email' ];

            return $this;
        }
    }

    $modelValidator = new ModelCreateValidator($this->app['validator']);
    
    if ($modelValidator->with($inputArray)
                       ->setUniqueId('email', $modelToUpdate->id)
                       ->addRuntimeValidationRules()
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();
        
        // Do some stuff for failing
    }


    public function update(ModelValidator $modelValidator) {

        if ($modelValidator->with($inputArray)
                           ->setUniqueId('email', $modelToUpdate->id)
                           ->addRuntimeValidationRules()
                           ->passes()) {
            // Do some stuff for passing
        } else {
            // Get the errors
            $validationErrors = $modelValidator->errors();
            
            // Do some stuff for failing
        }

    }