PHPackages                             laragear/rut - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. laragear/rut

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

laragear/rut
============

Tools to parse, validate and generate Chilean RUT in Laravel.

v5.0.0(2mo ago)711.9k—2.8%1MITPHPPHP ^8.3CI passing

Since Feb 23Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/Laragear/Rut)[ Packagist](https://packagist.org/packages/laragear/rut)[ Fund](https://github.com/sponsors/DarkGhostHunter)[ Fund](https://paypal.me/darkghosthunter)[ RSS](/packages/laragear-rut/feed)WikiDiscussions 5.x Synced 1mo ago

READMEChangelog (10)Dependencies (14)Versions (38)Used By (0)

Rut
===

[](#rut)

[![Latest Version on Packagist](https://camo.githubusercontent.com/cbb0a2ef56d0101b440acb099c0ebfe6a6b7e0a509f1ba93d5a4df4d55e67acc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c617261676561722f7275742e737667)](https://packagist.org/packages/laragear/rut)[![Latest stable test run](https://github.com/Laragear/Rut/workflows/Tests/badge.svg)](https://github.com/Laragear/Rut/actions)[![Codecov coverage](https://camo.githubusercontent.com/ea37f16c636a06f014026fe15e0f0bb519b532d8696eaa09861702c3fe3ad77a/68747470733a2f2f636f6465636f762e696f2f67682f4c617261676561722f5275742f67726170682f62616467652e7376673f746f6b656e3d35434f453858304a4d4a)](https://codecov.io/gh/Laragear/Rut)[![Maintainability](https://camo.githubusercontent.com/8ed8a9f20c457873657ccabd36130983ba4de414e53aa924376d469f21b65d07/68747470733a2f2f716c74792e73682f6261646765732f33363262636465372d383265312d346335612d383836642d3863323065663234353862302f6d61696e7461696e6162696c6974792e737667)](https://qlty.sh/gh/Laragear/projects/Rut)[![Sonarcloud Status](https://camo.githubusercontent.com/05be065120448251ec4d0e916fbfe0b4a53c3855ff91ffdf4f680a02050bb039/68747470733a2f2f736f6e6172636c6f75642e696f2f6170692f70726f6a6563745f6261646765732f6d6561737572653f70726f6a6563743d4c617261676561725f527574266d65747269633d616c6572745f737461747573)](https://sonarcloud.io/dashboard?id=Laragear_Rut)[![Laravel Octane Compatibility](https://camo.githubusercontent.com/70359a356da237cd29561bc5d0bb80baae775b5ff62f288ed324755382858342/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2532304f6374616e652d436f6d70617469626c652d737563636573733f7374796c653d666c6174266c6f676f3d6c61726176656c)](https://laravel.com/docs/13.x/octane#introduction)

Tools to parse, validate and generate Chilean RUT in Laravel.

```
use Laragear\Rut\Rut;

$rut = Rut::parse('18.765.432-1');

if ($rut->isValid()) {
    return 'Your RUT is valid!';
}
```

Keep this package free
----------------------

[](#keep-this-package-free)

[![](.github/assets/support.png)](https://github.com/sponsors/DarkGhostHunter)

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can **spread the word on social media**.

Requirements
------------

[](#requirements)

- PHP 8.3 or later
- Laravel 12 or later

Installation
------------

[](#installation)

Fire up Composer and require it into your project:

```
composer require laragear/rut
```

Creating a RUT
--------------

[](#creating-a-rut)

To create a RUT from an already **valid** source, instance a `Rut` object with the numbers and the verification digit, separately.

```
use Laragear\Rut\Rut;

$rut = new Rut(5138171, 8);
```

Otherwise, you may want to use `parse()` to create it from a single string. It will try its best to create a RUT instance from what is given, or throw an `InvalidRutException` if the string doesn't have the necessary characters to create a RUT.

```
use Laragear\Rut\Rut;

$rut = Rut::parse('5.138.171-8');
```

RUT Types
---------

[](#rut-types)

Officially, there are six types of RUT. To differentiate between them, you have access to `is...()` methods.

RUT TypeFromToType CheckPerson`    100.000`` 45.999.999``isPerson()`Foreign Investor Person` 46.000.000`` 47.999.999``isInvestor()`Foreign Investor Company` 47.000.000`` 47.999.999``isInvestorCompany()`Contingency` 48.000.000`` 59.999.999``isContingency()`Company` 60.000.000`` 99.999.999``isCompany()`Temporal`100.000.000``199.999.999``isTemporal()`Additionally, you have access to the `isPermanent()` method, which checks if the RUT is below 100.000.000.

```
use Laragear\Rut\Rut;

Rut::parse('76.482.465-2')->isPermanent(); // "true"

Rut::parse('76.482.465-2')->isTemporal(); // "false"
```

Important

This package considers RUT as valid when between 100.000 and 200.000.000, inclusive. Most (if not all) people using 99.999 or lower RUT numbers are deceased.

Generating RUTs
---------------

[](#generating-ruts)

The package comes with a convenient RUT `Generator` facade to create thousands or millions of random RUTs using fluid methods.

The `make()` method generates a [Collection](https://laravel.com/docs/collections) of 15 `Rut` by default, but you can set any number you want. Alternatively, you can use `makeOne()` to create just one random `Rut`.

```
use Laragear\Rut\Facades\Generator;

$ruts = Generator::make(10);

$rut = Generator::makeOne();
```

You can use `as...()` to make a given type of RUTs.

```
use Laragear\Rut\Facades\Generator;

$people = Generator::asPeople()->make(10);

$companies = Generator::asCompanies()->make(10);

$temporal = Generator::asTemporal()->makeOne();
```

If you plan to create several millions of RUTs, there is a high change you will come with duplicates. To avoid collisions, use the `unique()` method in exchange for a small performance hit to remove duplicates.

```
use Laragear\Rut\Facades\Generator;

$ruts = Generator::unique()->asCompanies()->make(10000000);
```

Serialization
-------------

[](#serialization)

By default, all `Rut` instances are serialized into text using a *strict* format, which includes thousands separators and hyphen to separate the RUT number from the RUT verification digit.

```
use Laragear\Rut\Rut;
use Laragear\Rut\RutFormat;

echo Rut::parse('51381718'); // "5.138.171-8"
```

There are three formats available to transform a RUT into a string: strict, basic and raw.

FormattingExampleDescriptionStrict`5.138.171-8`Default option. Serializes with a thousand separator and hyphen.Basic`5138171-8`No thousand separator, only the hyphen.Raw`51381718`No thousand separator nor hyphen.You may change which formatting type to serialize the RUT using one of the convenience methods.

```
echo $rut->formatStrict(); // "5.138.171-8"
echo $rut->formatBasic();  // "5138171-8"
echo $rut->formatRaw();    // "51381718"
```

Formatting a RUT can also be done programmatically through the `format()` method, which accepts a `Laragear\Rut\RutFormat` enum. If no argument is passed, it will use the default format.

```
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"
```

Tip

You can change the global format [in the configuration](#default-rut-format).

Validating a RUT
----------------

[](#validating-a-rut)

You should use the included [Validation Rules](#validation-rules) to validate RUTs in your input.

Otherwise, you can manually validate a RUT using `isValid()` or `isInvalid()` to check if it's mathematically valid or not, respectively.

```
use Laragear\Rut\Rut;

$rut = Rut::parse('5.138.171-8');

if ($rut->isValid()) {
    return "The Rut is valid!";
}
```

Using the `validate()` method will throw a `InvalidRutException` if it's invalid.

```
use Laragear\Rut\Rut;

Rut::parse('5.138.171-K')->validate(); // InvalidRutException: "The given RUT is invalid."
```

You can also validate RUT strings directly, or an already separated RUT, by using `check()` method.

```
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!";
}
```

Validation rules
----------------

[](#validation-rules)

All validation rules messages can be translated. You can add your own translation to these rules by publishing the translation files:

```
php artisan vendor:publish --provider="Laragear\Rut\RutServiceProvider" --tag="translations"
```

### `rut` rule

[](#rut-rule)

This checks if the RUT being passed is a valid RUT string. This automatically **cleans the RUT** from anything except numbers and the verification digit. Only then it checks if the resulting RUT is mathematically valid.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '14328145-0'
], [
    'rut' => 'rut'
]);

echo $validator->passes(); // true

$validator = Validator::make([
    'rut' => '65.00!!!390XXXX2'
], [
    'rut' => 'rut'
]);

echo $validator->passes(); // true
```

This may come handy in situations when the user presses a wrong button into an RUT input, so there is no need to ask the user to properly format a RUT. Afterwards, you can use the [Request RUT helpers](#request-rut-helper) to retrieve the RUT from the Request input or query.

The rule also accepts an `array` of RUTs. In that case, `rut` will succeed if all the RUTs are valid. This may come in handy when a user is registering a lot of people into your application.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => ['14328145-0', '12.343.580-K', 'thisisnotarut']
], [
    'rut' => 'rut'
]);

echo $validator->passes(); // false

$validator = Validator::make([
    'rut' => ['14328145-0', '12.343.580-K', '20881410-9']
], [
    'rut' => 'rut'
]);

echo $validator->passes(); // true
```

### `rut_strict` rule

[](#rut_strict-rule)

This works the same as `rut`, but it will validate RUTs that are also using the Strict RUT format: with a thousand separator and a hyphen before the Validation Digit.

It will return `false` even if there is one misplaced character or an invalid one.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '14.328.145-0'
], [
    'rut' => 'rut_strict'
]);

echo $validator->passes(); // true

$validator = Validator::make([
    'rut' => '1.4328.145-0'
], [
    'rut' => 'rut_strict'
]);

echo $validator->passes(); // false
```

This rule also accepts an `array` of RUTs. In that case, `rut_strict` will return true if all the RUTs are properly formatted and valid.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => ['1.4328.145-0', '12.343.580-K']
], [
    'rut.*' => 'required|rut_strict',
]);

echo $validator->paases(); // false
```

### `rut_exists` database rule

[](#rut_exists-database-rule)

Instead of using Laravel's [exists](https://laravel.com/docs/master/validation#rule-exists), you can use `rut_exists` in case your database has separated columns for the RUT Number and Verification Digit.

For this to work you need to set the table to look for, the *RUT number* column and *RUT verification digit* column, otherwise the rule will *guess* the column names by the attribute key and appending `_num` and `_vd`, respectively.

This rule automatically validates the RUT before doing the query.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '12.343.580-K'
], [
    'rut' => 'required|rut_exists:mysql.users,rut_num,rut_vd'
]);

echo $validator->passes(); // false
```

Since this also checks if the RUT is valid (not strict), it will fail if it's not, or the RUT doesn't exist in the database.

To customize the query, you can use the `Rule` class of Laravel with the method `rutExists`. Note that you can input the number and verification digit columns, or both, if you don't want to let the rule guess them, as it may incorrectly guess when using a wildcard.

```
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

$validator = Validator::make([
    'rut' => [
        'rut_1' => '12.343.580-K',
        'rut_2' => '13.871.792-5',
    ],
], [
    'rut' => [
        'required',
        Rule::rutExists('mysql.users', 'rut_num', 'rut_vd')->where('account_id', 1),
    ]
]);

echo $validator->passes(); // true
```

Tip

Database rules will normalize the verification *digit* as uppercase in the database for search queries.

### `num_exists` database rule

[](#num_exists-database-rule)

This validation rule checks if only the number of the RUT exists, without taking into account the verification digit. This is handy when the Database has an index in the number of the RUT, thus making this verification blazing fast.

This rule automatically validates the RUT before doing the query.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '12.343.580-K'
], [
    'rut' => 'required|num_exists:mysql.users,rut_num'
]);

echo $validator->passes(); // false
```

You can customize the underlying query using the `numExists`.

```
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

$validator = Validator::make([
    'rut' => '12.343.580-K',
], [
    'rut' => [
        'required',
        Rule::numExists('mysql.users', 'rut_num')->where('account_id', 1),
    ]
]);

echo $validator->passes(); // false
```

### `rut_unique` database rule

[](#rut_unique-database-rule)

This works the same as the `rut_exists` rule, but instead of checking if the RUT exists in the Database, it will detect if it doesn't. This rule works just like the [Laravel's `unique` rule works](https://laravel.com/docs/validation#rule-unique).

This rule automatically validates the RUT before doing the query.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '12.343.580-K'
], [
    'rut' => 'required|rut_unique:mysql.users,rut_num,rut_vd'
]);

echo $validator->passes(); // false
```

You can also exclude a certain ID or records from the Unique validation. For this, you need to use the `Rule` class.

```
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

$validator = Validator::make([
    'rut' => '12.343.580-K',
], [
    'rut' => [
        'required',
        Rule::rutUnique('mysql.users', 'rut_num')->ignore(request()->user()),
    ]
]);

echo $validator->passes(); // false
```

Tip

Database rules will normalize the verification *digit* as uppercase in the database for search queries.

Caution

**You should never pass any user controlled request input into the ignore method. Instead, you should only pass a system generated unique ID such as an auto-incrementing ID or UUID from an Eloquent model instance. Otherwise, your application will be vulnerable to an SQL injection attack.**

### `num_unique` database rule

[](#num_unique-database-rule)

This rule will check only if the **number** of the RUT doesn't exists already in the database, which is useful for Databases with an index solely on the number of the RUT. This rule also matches the [Laravel's `unique` rule works](https://laravel.com/docs/validation#rule-unique).

This rule automatically validates the RUT before doing the query.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '12.343.580-K'
], [
    'rut' => 'required|num_unique:mysql.users,rut_num'
]);

echo $validator->passes(); // false
```

You can also exclude a certain ID or records from the Unique validation. For this, you need to use the `Rule` class.

```
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

$validator = Validator::make([
    'rut' => '12.343.580-K',
], [
    'rut' => [
        'required',
        Rule::numUnique('mysql.users')->ignore(request()->user()->id),
    ]
]);

echo $validator->passes(); // false
```

Tip

Database rules will normalize the verification *digit* in the database for search queries.

Caution

**You should never pass any user controlled request input into the ignore method. Instead, you should only pass a system generated unique ID such as an auto-incrementing ID or UUID from an Eloquent model instance. Otherwise, your application will be vulnerable to an SQL injection attack.**

### Dummy RUTs Blacklist

[](#dummy-ruts-blacklist)

It's highly probable that you will use dummy RUTs like `11.111.111-1` or `88.888.888-8` while developing your application. While these are totally acceptable and valid, it's safer to *blacklist* them on production. To do that, set the [`blacklist_dummy_ruts` configuration to true](#blacklist-dummy-ruts).

The best way to do it is to enable the blocklist automatically on production environments:

```
return [
    'blacklist_dummy_ruts' => env('APP_ENV') === 'production'
]
```

With this enabled, dummy RUTs like `22.222.222-2` will be declared as invalid when trying to validating it, even if these are mathematically correct. For example, when checking if the RUT exists, it will be marked as invalid before even hitting the database.

```
use Illuminate\Support\Facades\Validator;

$validator = Validator::make([
    'rut' => '22.222.222-2'
], [
    'rut' => 'rut_exists:users'
]);

echo $validator->passes(); // false
```

#### Modifying the blacklist

[](#modifying-the-blacklist)

The blacklist of dummy RUTs resides in [`Laragear\Rut\ValidatesRut::DUMMY_RUTS`](src/ValidatesRut.php). If you're not happy with the default list, you may alter it through the `setDummies()` static method that will replace the entire list with the one you set.

```
use Laragear\Rut\ValidatesRut;

ValidatesRut::setDummies([
    '24.000.000-8',
    // ...
]);
```

If you want to go back to the original list, just call `setDummies()` without parameters.

```
use Laragear\Rut\ValidatesRut;

ValidatesRut::setDummies();
```

Important

When adding dummies, there will be no check for Verification Digit validity. Since only the RUT number is needed for verification, an invalid RUT added will be corrected when retrieved using `dummies()`.

Database Blueprint helper
-------------------------

[](#database-blueprint-helper)

If you're creating your database from the ground up, you don't need to manually create the RUT columns. Just use the `rut()` or `rutNullable()` helpers in the Blueprint:

```
Schema::create('users', function (Blueprint $table) {
    // $table->unsignedInteger('rut_num');
    // $table->char('rut_vd', 1);

    $table->rut();

    // ...
});

Schema::create('company', function (Blueprint $table) {
    // $table->unsignedInteger('rut_num')->nullable();
    // $table->char('rut_vd', 1)->nullable();

    $table->rutNullable();

    // ...
});
```

Tip

The `rutNullable()` method creates **both** Number and Verification Digit columns as nullable.

If you plan to use the RUT Number as an index, which may speed up queries to look for RUTs, you can just index the Number column by fluently adding `primary()`, `index()` or `unique()` depending on your database needs. This is because it has more performance sense to index only the Number rather than the whole RUT.

```
Schema::create('users', function (Blueprint $table) {
    // $table->unsignedInteger('rut_num')->primary();
    // $table->char('rut_vd', 1);

    $table->rut()->primary();

    // ...
});
```

Request RUT helper
------------------

[](#request-rut-helper)

This package includes the `rut()` macro helper for the `Request` instance, which retrieves a single RUT from an input or query.

```
use Illuminate\Http\Request;

public function show(Request $request)
{
    $request->validate([
        'person' => 'required|rut'
    ]);

    $rut = $request->rut('person');

    // ...
}
```

If the input is *iterable*, like an `array` or even a `Collection` instance, you will receive a `Collection` of `Rut` instances.

```
$request->validate([
    'people'   => 'required|array',
    'people.*' => 'rut'
]);

$ruts = $request->rut('people');
```

You can also retrieve multiple keys from the Request, which will also return a `Collection`.

```
$request->validate([
    'mom'        => 'required|rut',
    'dad'        => 'required|rut',
    'children'   => 'required|array'
    'children.*' => 'required|rut',
]);

$parents = $request->rut('mom', 'dad'); // Or $request->rut(['mom', 'dad']);
$children = $request->rut('children');
```

Important

It's imperative you validate your input before retrieving RUTs. If there is a malformed RUT, an exception will be thrown.

RUT traits for Eloquent Models
------------------------------

[](#rut-traits-for-eloquent-models)

This package contains the `HasRut` trait to use in Laravel Eloquent Models with tables that have separate RUT Number and RUT Verification digit.

This trait conveniently adds a RUT Scope to a model that has a RUT in its columns, and the `rut` property which returns a `Rut` instance.

```
namespace App\Models;

use Laragear\Rut\HasRut;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasRut;

    // ...
}
```

With that, you will have access to convenient RUT queries shorthands:

Method nameDescription`findRut()`Finds a record by the given RUT.`findManyRut()`Finds many records by the given RUTs.`findRutOrFail()`Finds a record by the RUT or fails.`findRutOrNew()`Finds a record by the RUT or creates one.`whereRut()`Creates a `WHERE` clause with the RUT number equal to the issued one.`whereRutNot()`Creates a `WHERE` clause excluding the given RUT.`orWhereRut()`Creates a `OR WHERE` clause with the RUT number equal to the issued one.`orWhereRutNot()`Creates a `OR WHERE` clause excluding the given RUT.`whereRutIn()`Creates a `WHERE IN` clause with the given RUTs.`whereRutNotIn()`Creates a `WHERE NOT IN` clause excluding the given RUTs.`orWhereRutIn()`Creates a `OR WHERE IN` clause with the given RUTs.`orWhereRutNotIn()`Creates a `OR WHERE NOT IN` clause excluding the given RUTs.`whereRutIsPerson()`Finds records with RUTs below 60.000.000.`orWhereRutIsPerson()`Finds records with RUTs below 60.000.000 or the next condition.`whereRutIsCompany()`Finds records with RUTs over 59.999.999 and below 100.000.000.`orWhereRutIsCompany()`Finds records with RUTs over 59.999.999 and below 100.000.000 or the next condition.`whereRutLike()`Creates a `LIKE` clause with the digits contained in the RUT number.`orWhereRutLike()`Creates a `OR LIKE` clause with the digits contained in the RUT number.`whereRutNotLike()`Creates a `NOT LIKE` clause with the digits not contained in the RUT number.`orWhereRutNotLike()`Creates a `OR NOT LIKE` clause with the digits not contained in the RUT number.Important

These RUT queries work over the RUT Number for convenience, as the RUT Verification Digit should be verified only on persistence.

These scopes can be used in your queries easily:

```
use App\Models\User;

$user = User::whereRut('20490006-K')->where('is_active', true)->find();
```

The `rut` property is dynamically created from the RUT Number and RUT Verification Digit columns, which uses a [Cast](https://laravel.com/docs/eloquent-mutators#attribute-casting) underneath.

```
echo $user->rut; // "20490006-K"
```

#### Setting the RUT columns

[](#setting-the-rut-columns)

By convention, the trait uses `rut_num` and `rut_vd` as the default columns to retrieve and save the RUT Number and RUT Verification Digit, respectively.

You can easily change it to anything your database is working with for the given Model:

```
class User extends Authenticatable
{
    use HasRut;

    protected const RUT_NUM = 'numero_rut';
    protected const RUT_VD = 'digito_rut';

    // ...
}
```

#### RUT Appended and columns hidden

[](#rut-appended-and-columns-hidden)

By default, the `rut` property is appended, and the underlying columns containing the RUT information are hidden. This enables compatibility with [Livewire real-time validation](https://laravel-livewire.com/docs/2.x/input-validation#real-time-validation).

```
{
    "id": 1,
    "name": "Taylor",
    "email": "taylor@laravel.com",
    "rut": "16.887.941-5"
}
```

To show the underlying RUT columns instead of the RUT string, simply make `shouldAppendRut()` in the model to return `false`.

```
/**
 * If the `rut` key should be appended, and hide the underlying RUT columns.
 */
public function shouldAppendRut(): bool
{
    return false;
}
```

This will effectively return both columns as normal properties.

```
{
    "id": 1,
    "name": "Taylor",
    "email": "taylor@laravel.com",
    "rut_num": 16887941,
    "rut_vd": "5"
}
```

If you need to make the `rut` key and the underlying columns visible, you may override the `shouldAppendRut()` method and return `false`.

```
public function shouldAppendRut(): bool
{
   $this->append('rut');

   return false;
}
```

##### Hiding the Primary Key as RUT Number

[](#hiding-the-primary-key-as-rut-number)

You may want to have your models using the RUT Number as primary key, especially if you want to keep users unique by the RUT. If that's your case, the library will automatically *show* the primary key instead of hiding it.

```
{
    "id": 16887941,
    "name": "Taylor",
    "email": "taylor@laravel.com",
    "rut": "16.887.941-5"
}
```

If you still want to hide the primary key, you can make the `shouldShowPrimaryKeyIfIsRutNum()` in your model.

```
/**
 * If the primary key of the model should be hidden if it's the RUT Num.
 */
public function shouldShowPrimaryKeyIfIsRutNum(): bool
{
    return false;
}
```

Hiding the Primary Key, which is the RUT Number, won't make hide the RUT property on serialization.

```
{
    "name": "Taylor",
    "email": "taylor@laravel.com",
    "rut": "16.887.941-5"
}
```

Livewire &amp; Filament
-----------------------

[](#livewire--filament)

This library comes with some utilities if your application is using [Filament](https://filamentphp.com/), or just [Livewire](https://livewire.laravel.com).

### RUT Synthesizer

[](#rut-synthesizer)

If you're using Livewire, this library will automatically register the `Laragear\Rut\Livewire\Synth\RutSynth` [synthesizer](https://livewire.laravel.com/docs/synthesizers) to serialize the `Laragear\Rut\Rut` instance back and forth the frontend. If you don't want to register it and use your own, set the [configuration](#register-synthesizer) to *falsy*.

The RUT Synthesizer uses the `rut` as key in the frontend. You may change it using the `$key` static property. A good place to put this logic is in the `boot()` method of your `AppServiceProvider` file.

```
use Laragear\Rut\Livewire\Synthesizers\RutSynth;

public function boot()
{
    RutSynth::$key = 'my-rut-key';
}
```

By default, the Synthesizer will *dehydrate* the input value using the [default RUT format](#default-rut-format) set in your application. This means that if a RUT input only contains numbers, after dehydration, the value will be returned using the RUT format of your app.

If you wish to dehydrate using a different format, usually to match the format on the frontend, you may set the `$format` static property to the `RutFormat` of your choice. This will only apply to dehydration.

```
use Laragear\Rut\Livewire\Synthesizers\RutSynth;
use Laragear\Rut\RutFormat;

public function boot()
{
    RutSynth::$key = 'my-rut-key';
    RutSynth::$format = RutFormat::Raw;
}
```

### Filament RUT Column

[](#filament-rut-column)

If you may wish to show a column of RUT inside a Filament Table, you may use the `Laragear\Rut\Filament\Tables\Columns\RutColumn` class. It's based on the native `Filament\Tables\Columns\TextColumn` class, so it supports all its features.

```
use Filament\Tables\Table;
use Laragear\Rut\Filament\Tables\Columns\RutColumn;

public static function table(Table $table)
{
    $table->columns([
        RutColumn::make('rut')
            ->alignCenter()
            ->tooltip('The user RUT in the application.');
    ]);
}
```

#### RUT Column source type

[](#rut-column-source-type)

By default, the RUT is generated from a state that is already a `Rut` instance o a RUT string. If you're using a different source type, like only the RUT Number or an array with the RUT Number and Verification Digit separated, you may use the `fromRutNumber()` or `fromRutArray()`, respectively.

```
use Filament\Tables\Table;
use Laragear\Rut\Filament\Tables\Columns\RutColumn;

public static function table(Table $table)
{
    $table->columns([
        RutColumn::make('rut')->fromRutNumber(),
        RutColumn::make('business_rut')->fromRutArray()
    ]);
}
```

Tip

When using `fromRutArray()`, the array is [*spread*](https://wiki.php.net/rfc/spread_operator_for_array) into the Rut constructor. When not using a list array (numeric indexes), then use the `num` and `vd` keys for the RUT Number and Verification Digit in your data source, respectively:

```
$rut = [
    'num' => 18765432,
    'vd' => 1,
];
```

#### RUT Column Formatting

[](#rut-column-formatting)

By default, the RUT is formatted [using your configuration](#default-rut-format). If you wish to format the state using a different format, you may use the `formatAsRaw()`, `formatAsBasic()` and `formatAsStrict()` methods.

```
use Filament\Tables\Table;
use Laragear\Rut\Filament\Tables\Columns\RutColumn;

public static function table(Table $table)
{
    $table->columns([
        RutColumn::make('rut')->formatAsRaw(),
    ]);
}
```

### Filament RUT input

[](#filament-rut-input)

For RUT inputs, you may use the `Laragear\Rut\Filament\Forms\Components\RutInput` class, which is based from the native `Filament\Forms\Components\TextInput` class.

The Input only accepts numbers and `k|K`. While the user uses the input, the RUT gets automatically formatted strictly, and on the frontend a RUT pattern is enforced at input level.

```
use Livewire\Form
use Laragear\Rut\Filament\Forms\Components\RutInput;

public static function form(Form $form): Form
{
    return $form->schema([
        RutInput::make('rut')->required(),
    ]);
}
```

##### Hiding the Primary Key as RUT Number

[](#hiding-the-primary-key-as-rut-number-1)

You may want to have your models using the RUT Number as primary key, especially if you want to keep users unique by the RUT. If that's your case, the library will automatically *show* the primary key instead of hiding it.

```
{
    "id": 16887941,
    "name": "Taylor",
    "email": "taylor@laravel.com",
    "rut": "16.887.941-5"
}
```

If you still want to hide the primary key, you can make the `shouldShowPrimaryKeyIfIsRutNum()` in your model.

```
/**
 * If the primary key of the model should be hidden if it's the RUT Num.
 */
public function shouldShowPrimaryKeyIfIsRutNum(): bool
{
    return false;
}
```

Hiding the Primary Key, which is the RUT Number, won't make hide the RUT property on serialization.

```
{
    "name": "Taylor",
    "email": "taylor@laravel.com",
    "rut": "16.887.941-5"
}
```

Configuration
-------------

[](#configuration)

This package works flawlessly out of the box, but you may want to change how a `Rut` is formatted as a string using the global configuration. You can publish it using Artisan:

```
php artisan vendor:publish --provider="Laragear\Rut\RutServiceProvider" --tag="config"
```

You will receive the `config/rut.php` config file like this:

```
use Laragear\Rut\RutFormat;

return [
    'format' => RutFormat::Strict,
    'json_format' => null,
    'blacklist_dummy_ruts' => false,
    'uppercase' => true,
    'synthesizer' => true,
];
```

### Default RUT Format

[](#default-rut-format)

```
use Laragear\Rut\RutFormat;

return [
    'format' => RutFormat::DEFAULT,
];
```

By default, RUTs are [*strictly* formatted](#serialization). This config alters how RUTs are serialized by default as string in your application.

### JSON format

[](#json-format)

```
use Laragear\Rut\RutFormat;

return [
    'json_format' => null,
];
```

For the case of JSON, RUT are cast as a string using the global format when this is `null`. You can set any format to use when serializing into JSON exclusively.

```
use Laragear\Rut\Rut;
use Laragear\Rut\RutFormat;

config()->set('rut.format_json', RutFormat::Raw)

Rut::parse('5.138.171-8')->format(); // "5.138.171-8"
Rut::parse('5.138.171-8')->toJson(); // "51381718"
```

Alternatively, you can override the configuration by using a callback to create your own JSON format. The callback accepts the `Rut` instance, and it should return an `array` or a `string` to be serialized into JSON. A good place to put this logic is in the `boot()` method of your `AppServiceProvider` file.

```
use Laragear\Rut\Rut;

public function boot()
{
    Rut::$jsonFormat = function (Rut $rut) {
        return ['num' => $rut->num, 'vd' => $rut->vd];
    }

    Rut::parse('5.138.171-8')->toJson(); // "{"num":5138171,"vd":"8"}"
}
```

### Blacklist dummy RUTs

[](#blacklist-dummy-ruts)

```
return [
    'blacklist_dummy_ruts' => false,
];
```

When developing, you may use dummy RUTs like `11.111.111-1` or `76.000.000-0` to create fake data in the database. If this may seem like a problem on production, you may always blacklist these RUT's.

```
return [
    'blacklist_dummy_ruts' => env('APP_ENV') === 'production',
];
```

Additionally, you may [change the blacklist](#modifying-the-blacklist) to add, replace, or remove RUTs that should be considered *dummy*.

### Verification Digit Case

[](#verification-digit-case)

```
return [
    'uppercase' => true,
];
```

Since the Verification Digit can be either a single digit or the letter `K`, it's usually good idea to keep the character case consistent: always work with uppercase or lowercase across all the application.

The `Rut` instance by default will use uppercase `K`, but you can change it to lowercase globally by setting this to `false`. This will affect all `Rut` instances.

```
use Laragear\Rut\RutFormat;
use Laragear\Rut\Rut;

config()->set('rut.uppercase', false)

$rut = Rut::parse('12351839-K');

$rut->format(); // "12.351.839-k"
$rut->toJson(); // "12.351.839-k"
```

Tip

This doesn't affect database rules, as the verification digit is normalized automatically in the database query.

### Register synthesizer

[](#register-synthesizer)

```
return [
    'synthesizer' => true,
]
```

This controls if the [Livewire Synthesizer](#livewire--filament) should be automatically registered or not. Any *falsy* value will disable it so you may register your own.

PhpStorm stubs
--------------

[](#phpstorm-stubs)

For users of PhpStorm, there is a stub file to aid in macro autocompletion for this package. You can publish it using the `phpstorm` tag:

```
php artisan vendor:publish --provider="Laragear\Rut\RutServiceProvider" --tag="phpstorm"
```

The file gets published into the `.stubs` folder of your project. You should point your [PhpStorm to these stubs](https://www.jetbrains.com/help/phpstorm/php.html#advanced-settings-area).

Laravel Octane compatibility
----------------------------

[](#laravel-octane-compatibility)

- There are no singletons using a stale application instance.
- There are no singletons using a stale config instance.
- There are no singletons using a stale request instance.
- `Rut` static properties are only written once at boot time from config.

There should be no problems using this package with Laravel Octane.

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

License
=======

[](#license)

This specific package version is licensed under the terms of the [MIT License](LICENSE.md), at the time of publishing.

[Laravel](https://laravel.com) is a Trademark of [Taylor Otwell](https://github.com/TaylorOtwell/). Copyright © 2011–2026 Laravel LLC.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance86

Actively maintained with recent releases

Popularity32

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 87.4% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~61 days

Recently: every ~13 days

Total

25

Last Release

71d ago

Major Versions

1.x-dev → v2.0.02023-10-03

2.x-dev → v3.0.02024-03-06

3.x-dev → v4.0.02025-02-18

4.x-dev → v5.0.02026-03-08

PHP version history (5 changes)v1.0.0PHP ^8.0.2

v1.2.0PHP 8.\*

v2.0.0PHP ^8.1

v4.0.0PHP ^8.2

v5.0.0PHP ^8.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5141911?v=4)[Italo](/maintainers/DarkGhostHunter)[@DarkGhostHunter](https://github.com/DarkGhostHunter)

---

Top Contributors

[![DarkGhostHunter](https://avatars.githubusercontent.com/u/5141911?v=4)](https://github.com/DarkGhostHunter "DarkGhostHunter (221 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

chilelaravelphprutvalidationvalidatorlaravelrutchile

### Embed Badge

![Health badge](/badges/laragear-rut/health.svg)

```
[![Health](https://phpackages.com/badges/laragear-rut/health.svg)](https://phpackages.com/packages/laragear-rut)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M107](/packages/propaganistas-laravel-phone)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8703.0M17](/packages/yajra-laravel-oci8)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
