Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Faker Chile Laravel Package

astersnake/faker-chile

Faker Chile adds Chilean fake data to Faker, including RUTs, names, addresses, regions, communes, phone numbers, and companies. Useful for seeding Laravel apps and testing with realistic local records.

View on GitHub
Deep Wiki
Context7

Getting Started

astersnake/faker-chile extends Faker with Chilean locale data (RUT, names, addresses, communes/regions, phone numbers). Version 1.0.4 is the first release worth targeting in a modern stack: it fixes RUT generation, adds Laravel 11 and PHP 8.2/8.3 support, and clears out stale Dependabot pins.

Minimal path:

  1. composer require astersnake/faker-chile --dev (it is almost always a dev/test dependency — you rarely generate fake Chileans in production).
  2. Confirm the version constraint resolves to ^1.0.4. Anything older can emit RUTs with a wrong check digit, which will blow up in assertDatabaseHas / validation tests.
  3. Register the provider. In plain Faker:
$faker = Faker\Factory::create('es_CL');
$faker->addProvider(new Astersnake\FakerChile\Providers\ChileProvider($faker));

In Laravel, if the package service provider is auto-discovered (check vendor/astersnake/faker-chile/composer.json → extra.laravel.providers), fake() and $this->faker in factories should already have the formatters. If not, bind it yourself in a FakerServiceProvider (see below).

First use case: a UserFactory / CompanyFactory that needs a valid Chilean RUT for feature tests around registration, invoicing, or SII-style documents. Look first at the provider class (src/Providers/ChileProvider.php) — the public methods there are your actual API surface, and the README's formatter list is the second thing to read because method names don't always mirror core Faker (rut() vs chileanRut() etc.).

Implementation Patterns

Bind a configured generator once, use fake() everywhere. Rather than adding the provider in every test, resolve Faker through the container:

// app/Providers/FakerServiceProvider.php
public function register(): void
{
    $this->app->singleton(\Faker\Generator::class, function () {
        $faker = \Faker\Factory::create('es_CL');
        $faker->addProvider(new \Astersnake\FakerChile\Providers\ChileProvider($faker));
        return $faker;
    });
}

Laravel's fake() helper resolves Faker\Generator from the container, so every factory and seeder inherits the Chilean formatters with no per-test boilerplate.

Factory states for Chilean entities. Wrap the package calls in named states so intent stays readable and you can swap providers later:

public function chilean(): static
{
    return $this->state(fn () => [
        'rut'     => fake()->rut(),
        'name'    => fake()->name(),
        'address' => fake()->address(),
        'phone'   => fake()->phoneNumber(),
    ]);
}

Seed deterministically for snapshot-style assertions. $this->seed(1234) before generating, or use fake()->seed() — combined with fake()->unique()->rut() you get stable data across runs without collisions in a unique index.

Pair geography data with geography data. If the provider exposes region/commune formatters, generate the commune first and derive the region from it (or hard-code a small map) rather than calling both independently — a Santiago address in the Aysén region is the classic tell of a fake Chilean record, and it will bite you in any test that filters by region.

Use it as a test fixture source, not a runtime generator. The realistic integration is Pest/PHPUnit tests and db:seed for local demos. If you need fake Chilean data in staging, prefer a dedicated seeder command guarded by app()->environment('local').

Generate the RUT and validate it in the same test. The point of 1.0.4 is that rut() now yields check-digit-correct values. Prove it in one test so a future downgrade or fork is caught immediately:

it('generates valid RUTs', function () {
    foreach (range(1, 100) as $_) {
        expect(ChileanRut::isValid(fake()->rut()))->toBeTrue();
    }
});

Gotchas and Tips

  • The RUT fix is the reason to upgrade. 1.0.4 (PR #10) corrects check-digit generation. If you pinned 1.0.3, any test asserting a valid RUT, or a factory feeding a form request with rut validation, may have been passing only because it never actually validated. Pre-1.0.4 fixtures in your repo may now look "wrong" — regenerate them.
  • The RUT still isn't validated by this package. It generates; it does not ship a validation rule. Add your own rule (mod-11, DV 0-9 or K/k) or a small dedicated validator package. Do not assume fake()->rut() output passes assertDatabaseHas on a column with a DB-level constraint on formatting.
  • Format ambiguity. RUTs come out in one canonical format (typically with dots and hyphen, e.g. 12.345.678-5). If your DB column or API expects 123456785, normalize in the factory via str_replace(['.', '-'], '', ...) rather than patching the provider. Also normalize the check digit case — K vs k breaks naive string comparisons.
  • Dependabot noise is CI-only. PRs #4–#7 bump GitHub Actions (fetch-metadata, laravel-pint-action). No runtime impact; skip them when reading the changelog for upgrade risk.
  • Composer constraints were broadened, not narrowed. PRs #11/#12 add Laravel 11 and PHP 8.2/8.3. That should keep Laravel 9/10 installs working, but verify on your lowest supported matrix — an unconstrained illuminate/support in a small package is exactly where PHP 8.1 deprecations hide.
  • Faker\Factory::create('es_CL') alone is not enough. The locale string selects the base Spanish provider, not the Chilean one. Without addProvider(), fake()->rut() throws BadMethodCallException: Unknown format "rut". If you see that, your container binding isn't winning over Laravel's default Faker singleton — check bind vs singleton and provider registration order.
  • unique() is finite and stateful. fake()->unique()->rut() will eventually exhaust and throw. In a loop of hundreds of records, prefer a while with dedupe against the DB, or reset with fake()->unique(true) between tests.
  • Extension point: the provider is a plain Faker provider. If you need SII activity codes, Chilean bank names, or passport formats it doesn't cover, subclass ChileProvider and add methods there rather than scattering fake()->numerify() hacks through factories — keeps the whole team on one API.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
diephp/sequences
users-au/socialite-provider
twidpay/twid-logger
mrnewport/laravel-plaid
mrnewport/laravel-repo
mrnewport/laravel-docsign
mrnewport/laravel-stow
mrnewport/laravel-flow
mrnewport/laravel-priceable
mrnewport/laravel-nestedterms
fredmeng/laravel-apidoc-generator
itstructure/laravel-multilingual-tools
pdustdar/elasticsearch
markupai/php-sdk
rlacerda83/lumem-microservice-shipment
uni-method/symfony-lib
tacticmedia/scim-server-bundle
neika-ai/symfony-bundle
mattleads/agent-publishing-bundle
glavweb/framework-bundle