1. Go to this page and download the library: Download laragear/rut 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/ */
laragear / rut example snippets
use Laragear\Rut\Rut;
$rut = Rut::parse('18.765.432-1');
if ($rut->isValid()) {
return 'Your RUT is valid!';
}
use Laragear\Rut\Rut;
$rut = new Rut(5138171, 8);
use Laragear\Rut\Rut;
$rut = Rut::parse('5.138.171-8');
use Laragear\Rut\Rut;
Rut::parse('76.482.465-2')->isPermanent(); // "true"
Rut::parse('76.482.465-2')->isTemporal(); // "false"
use Laragear\Rut\Facades\Generator;
$ruts = Generator::make(10);
$rut = Generator::makeOne();
use Laragear\Rut\Rut;
use Laragear\Rut\RutFormat;
$rut = Rut::parse('5.138.171-8');
$rut->format(); // "5.138.171-8"
$rut->format(RutFormat::Strict); // "5.138.171-8"
$rut->format(RutFormat::Basic); // "5138171-8"
$rut->format(RutFormat::Raw); // "51381718"
use Laragear\Rut\Rut;
$rut = Rut::parse('5.138.171-8');
if ($rut->isValid()) {
return "The Rut is valid!";
}
use Laragear\Rut\Rut;
Rut::parse('5.138.171-K')->validate(); // InvalidRutException: "The given RUT is invalid."
use Laragear\Rut\Rut;
if (Rut::check('5.138.171-8')) {
return "This RUT is valid!";
}
if (Rut::check(5138171, '8')) {
return "This RUT is also valid!";
}
namespace App\Models;
use Laragear\Rut\HasRut;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
use HasRut;
// ...
}
use App\Models\User;
$user = User::whereRut('20490006-K')->where('is_active', true)->find();
echo $user->rut; // "20490006-K"
class User extends Authenticatable
{
use HasRut;
protected const RUT_NUM = 'numero_rut';
protected const RUT_VD = 'digito_rut';
// ...
}
/**
* If the `rut` key should be appended, and hide the underlying RUT columns.
*/
public function shouldAppendRut(): bool
{
return false;
}
public function shouldAppendRut(): bool
{
$this->append('rut');
return false;
}
/**
* If the primary key of the model should be hidden if it's the RUT Num.
*/
public function shouldShowPrimaryKeyIfIsRutNum(): bool
{
return false;
}