1. Go to this page and download the library: Download pittacusw/chilean-bundle 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/ */
use Freshwork\ChileanBundle\Rut;
$rut = new Rut('11.111.111', '1');
$rut->validate(); //true
(new Rut('12345678', '5'))->validate(); //true
Rut::parse('11.111.111-1')->validate(); //true
Rut::parse('11111111-1')->validate(); //true
Rut::parse('12.345.678-5')->validate(); //true
Rut::parse('123456785')->validate(); //true
Rut::parse('1.23.45.6.7.8-5')->validate(); //true. It escapes all the dots and dashes.
Rut::set('10.123.123', '5'); //return true
Rut::parse('12345678-5')->isValid(); //true
Rut::parse('12.345.678-9')->validate(); //false
Rut::parse('12.3k5.6L8-9')->validate(); //throw Freshwork\ChileanBundle\Exceptions\InvalidFormatException
Rut::set('12.345.678')->validate(); // throw exception. We didn't set the verification number
Rut::parse('12.3k5.6L8-9')->quiet()->validate(); //return false. No exception
Rut::parse('12.345.678-9')->fix()->format(); //return '12.345.678-5'
//Set a new rut without setting any verification number
Rut::set('12345678')->fix()->format(); //return '12.345.678-5'
//Set a new rut with an invalid verification number that will be replaced
Rut::set('12345678', '6')->fix()->format(); //return '12.345.678-5'
Rut::parse('12.345.678-9')->validate(); //return false
Rut::parse('12.345.678-9')->fix()->validate(); //return true
...
class ClientController extends Controller{
...
use ValidateRequests;
...
public function store(Request $request) {
$this->validate($request, [
`nombre' => '
use \Freshwork\ChileanBundle\Rut;
//We loop 100 times
for($i = 0; $i < 10; $i++)
{
//generate random number between 1.000.000 and 25.000.000
$random_number = rand(1000000, 25000000);
//We create a new RUT wihtout verification number (the second paramenter of Rut constructor)
$rut = new Rut($random_number);
//The fix method calculates the
echo $rut->fix()->format() . " \n";
}
//Output (random)
17.062.139-5
18.815.969-9
14.287.543-8
13.864.006-K
16.724.081-K
20.465.345-3
13.294.672-8
11.102.906-7
8.333.479-7
7.661.557-8