PHP code example of vector88 / laravel-validation

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

    

vector88 / laravel-validation example snippets

 php


namespace App\Http\Controllers;

use Validator;
use Validation;

class ValidationController extends Controller
{
	
	protected $validation;
	
	public function __construct() {
		$this->validation =
			Validation::make()
				->field( 'name' )->isRequired()->isString()->hasMin( 4 )->hasMax( 16 )
				->field( 'age' )->isInteger()->hasMin( 0 )->hasMax( 120 );
	}
	
	public function angular() {
		return $this->validation
			->provide( 'angular' )
			->allAttributes();
	}
	
	public function laravel() {
		return $this->validation
			->provide( 'laravel' )
			->allAttributes();
	}
	
	public function validator() {
		$data = [ 'name' => 'Jon', 'age' => 148.7 ];
		$rules = $this->validation->rules();
        $validator = Validator::make( $data, $rules );
		return $validator->errors();
	}
}