Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
[![Maintainability](https://qlty.sh/badges/362bcde7-82e1-4c5a-886d-8c20ef2458b0/maintainability.svg)](https://qlty.sh/gh/Laragear/projects/Rut)
[![Sonarcloud Status](https://sonarcloud.io/api/project_badges/measure?project=Laragear_Rut&metric=alert_status)](https://sonarcloud.io/dashboard?id=Laragear_Rut)
[![Laravel Octane Compatibility](https://img.shields.io/badge/Laravel%20Octane-Compatible-success?style=flat&logo=laravel)](https://laravel.com/docs/13.x/octane#introduction)
[![Laravel Boost Compatibility](https://img.shields.io/badge/Laravel%20Boost-Compatible-purple?logo=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCEtLSBMaWNlbnNlOiBNSVQuIE1hZGUgYnkgZnJhbWV3b3JrN2lvOiBodHRwczovL2dpdGh1Yi5jb20vZnJhbWV3b3JrN2lvL2ZyYW1ld29yazctaWNvbnMgLS0+CjxzdmcgZmlsbD0iI2ZmZmZmZiIgdmlld0JveD0iMCAwIDU2IDU2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjxwYXRoIGQ9Ik0gMjYuNjg3NSAxMi42NjAyIEMgMjYuOTY4NyAxMi42NjAyIDI3LjEwOTQgMTIuNDk2MSAyNy4xNzk3IDEyLjIzODMgQyAyNy45MDYyIDguMzI0MiAyNy44NTk0IDguMjMwNSAzMS45Mzc1IDcuNDU3MCBDIDMyLjIxODcgNy40MTAyIDMyLjM4MjggNy4yNDYxIDMyLjM4MjggNi45NjQ4IEMgMzIuMzgyOCA2LjY4MzYgMzIuMjE4NyA2LjUxOTUgMzEuOTM3NSA2LjQ3MjYgQyAyNy44ODI4I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uNjI1MCA1NC43MzA1IDMxLjIzNDQgNTQuNzMwNSBaIi8+PC9zdmc+)](https://laravel.com/docs/13.x/boost)

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

Expand Down Expand Up @@ -1065,6 +1066,20 @@ The file gets published into the `.stubs` folder of your project. You should poi

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

## Laravel Boost compatibility

This package includes Laravel Boost AI Guidelines for your agents. Also included are the following AI Skills:

- Eloquent Integration
- Seeding and Testing
- Validation

After installing this package, ensure your Laravel Boost files are updated using the `boost:update` command:

```shell
php artisan boost:update
```

## Security

If you discover any security-related issues, please email darkghosthunter@gmail.com instead of using the issue tracker.
Expand Down
29 changes: 29 additions & 0 deletions resources/boost/guidelines/core.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Laragear Rut Boost AI Guideline

Strict directives for AI code generation involving Chilean RUT management with the laragear/rut package.

### 1. Core Principles

- **Check functions and signatures:** Do not rely on internal knowledge, proactively read the source code of this package for correct method names and signatures.
- **No Manual Calculation:** Never write custom regex, math loops, or module 11 algorithms to validate or format Chilean RUTs. Always rely on the `Laragear\Rut\Rut` class or package features.
- **Strict Format Handling:** Keep clean RUT database representations (`'123456789'`) isolated from user-facing formatted strings (`'12.345.678-9'`).

### 2. Model Casting

- **Cast Attribute:** Always use `Laragear\Rut\Casts\CastRut` in the Eloquent model `$casts` array or `cast()` method.
- **Database Storage:** Store RUTs by using the `rut()` macro available in the `Illuminate\Database\Schema\Builder` class.
- **Model Storage:** Use valid RUT string or number to set on the model property, like `$model->rut = '15.518.258-K'`.

### 3. Validation

- **Rules:** Use the `rut` rule for general validation, and `rut:strict` only when the exact punctuation format (dots and dash) is strictly required.
- **Pre-validation:** When RUT inputs are split into number and verification digit, standardize inputs inside `prepareForValidation()` using `Rut::parse($value)->formatStrict()`.

### 4. Testing & Seeding

- **Mocking:** Always use `Laragear\Rut\Facades\Generator` class methods instead of hardcoded strings or custom faker patterns.
- **Generators:** Use the explicit `asCompany()` or `asPerson()` genrator builder methods to target specific testing scenarios.

### 5. Production environments

- **Block dummy RUTs:** The `rut.blacklist_dummy_ruts` config is opt-in. Ask the developer to block dummy RUTs. Suggest using `env('APP_ENV') === 'production'` to block only on production. If unable to ask, or the config file does not exist, do nothing.
75 changes: 75 additions & 0 deletions resources/boost/skills/eloquent/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---
name: laragear-rut-eloquent
description: Manage Chilean RUTs in Eloquent models with custom casting and scopes.
---

## Laragear RUT Eloquent Integration

### When to use this skill

Use this skill when storing, casting, or querying Chilean RUT attributes inside Eloquent models.

### Set up

Locate the model that will use RUTs and add the `Laragear\Rut\HasRut` trait.

```php
use Illuminate\Database\Eloquent\Model;
use Laragear\Rut\HasRut;

class User extends Model
{
use HasRut;

// ...
}
```

Ensure the Model migration contains the RUT columns:

```php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
// ...

$table->rut(); // Add the RUT number and verification digit columns

// ...
});
}
}
```

### Features

#### RUT Casting

Cast database strings automatically into `Rut` value objects for formatting helpers.

```php
use Laragear\Rut\Casts\CastRut;

protected function casts()
{
return [
'rut' => CastRut::class,
];
}
```

#### RUT Query Scopes

When using the `Laragear\Rut\HasRut` trait in the model, the model query builder will have access to many RUT Local Scopes. Read that trait PHPDoc for a list of available methods.

```php
use App\Models\User;

$user = User::findByRut('15.518.258-K');
```
36 changes: 36 additions & 0 deletions resources/boost/skills/seeding/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
name: laragear-rut-seeding
description: Generate valid Chilean RUTs for model factories and database seeders.
---

## Laragear RUT Seeding and Testing

### When to use this skill

Use this skill when generating mock RUTs for database seeders, tests, or factory definitions.

### Features

#### Random RUT Generation

Generate mathematically correct, randomized Chilean RUTs.

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

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

#### Targeted RUT Generation

Generate valid company or natural person RUT ranges dynamically.

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

// Generate a company RUT (> 50,000,000)
$companyRut = Generator::asCompanies()->makeOne();

// Generate 100 natural person RUTs (< 50,000,000) without duplicates.
$personRut = Generator::asPeople()->unique()->make(100);
```
63 changes: 63 additions & 0 deletions resources/boost/skills/validation/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
name: laragear-rut-validation
description: Validate Chilean RUT inputs in Laravel applications.
---

## Laragear RUT Validation

### When to use this skill

Use this skill when validating or checking Chilean RUTs in Requests, Form Requests, APIs, or controllers.

### Features

#### Request Validation

Validate RUT inputs with the automatic rut rule.

```php
use Illuminate\Http\Request;

public function save(Request $request)
{
$request->validate([
'rut' => 'required|rut|unique:contacts,rut',
]);

// ...
}
```

#### Object validation

Outside the request lifecycle, use the `check()` method to check if a RUT string is correct or not.

```php
use Laragear\Rut\Rut;

if (Rut::check('invalid-rut')) {
return 'The RUT is invalid';
}
```

#### Type validation

With a `Laragear\Rut\Rut` instance use `is{Type}()` to check if a RUT is part of a RUT boundary type:

- `isPerson()`,
- `isInvestor()`,
- `isInvestmentCompany()`
- `isContingency()`
- `isCompany()`
- `isTemporal()`
- `isPermanent()`.

```php
use Laragear\Rut\Rut;

$rut = Rut::parse($input);

if (! $rut->isPerson()) {
return 'Only RUT for Natural People are accepted.';
}
```
2 changes: 2 additions & 0 deletions src/RutServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
protected function registerRules(): void
{
$this->callAfterResolving('validator', static function (Factory $validator, Application $app): void {
ValidatesRut::$blacklistDummyRuts = $app->make('config')->get('rut.blacklist_dummy_ruts', false);

Check failure on line 76 in src/RutServiceProvider.php

View workflow job for this annotation

GitHub Actions / 3️⃣ Static Analysis

Access to an undefined static property Laragear\Rut\ValidatesRut::$blacklistDummyRuts.

$translator = $app->make('translator');

foreach (static::RULES as [$rule, $extension, $key]) {
Expand Down
Loading