laravel-faker-provider-extensions
Narrow trigger extracted from skills/laravel-conventions §7.47–§7.51, so a factory attribute
carrying generation logic routes here directly instead of only through the whole Laravel block.
When
Writing or reviewing a factory definition(), a factory state, or a seeder, where one attribute's
value needs more than a single generator call to produce.
Steps
- A factory attribute is one Faker call. The moment it needs logic — concatenation, a retry
loop, a hand-typed vocabulary array,
ucfirst()/strtoupper() wrapped around a call — that logic
moves into a Faker\Provider\Base subclass, in the project, on the spot.
- Register the provider once, through a service provider's
boot() ($faker->addProvider(new ...)), never inside the factory, the seeder, or a test's setUp() — registering per-call or
per-test leaks the provider into every test that runs after the first one in the same process.
- Keep helper methods
private/protected. Every public method on the provider becomes a
generator ($faker->yourMethod()); an internal helper made public is callable, and collidable,
the same way.
- Check the bundled and locale
fakerphp/faker providers before writing your own. A value that
only looks plausible (an unchecked digit string standing in for something with a real check digit
or format) is a fixture that silently drifts from what the application's own validation rules
require.
- Seeders follow the same rule. Falling back to an inline string when no provider covers a value
reintroduces the problem one call site removed from the factory.
unique() on a bounded set breaks the suite, not just one test. Faker's unique() modifier
remembers every value it has drawn on the Faker instance, and factories share that instance for the
whole process — fine against an effectively unbounded generator (email(), uuid()), but a
bounded set (an enum, a fixed vocabulary array, a provider method with few possible outputs)
exhausts the pool after enough factory calls across the run, and every call after that throws. Use
Laravel's factory Sequence (or a plain counter passed into the provider) instead of unique()
whenever the underlying value space is small.
Output / checkpoint
No factory or seeder attribute in the diff builds its value with anything beyond one generator call
and its modifiers (nullable(), a regex/format constraint) — every attribute needing logic resolves
to a provider method, registered once, and unique() is only used against an unbounded value space.
Guardrails
- This is the generation-logic half of
skills/laravel-conventions §7's config/commands/seeders/
factories section — read §7.47–§7.51 for the full argument and the collision risk.
laravel-idempotent-seeders and laravel-seed-new-features cover what a seeder's rows must do;
this skill covers what generates the values those rows carry.
- A user override ("just inline it, this is a throwaway repro") wins without argument — this is a
default for new code, not a rule to enforce against an explicit instruction.
Origin
Mined from an org skill catalogue's Laravel plugin (a custom-faker-extensions skill and a paired
faker-extensions skill, shipped 2026-09-24), rewritten around the public fakerphp/faker
extension mechanism (Faker\Provider\Base, addProvider()) rather than the source's own internal
Faker fork — that package's kebab-cased-registry-collision and extra.faker-composer-key mechanics
are specific to a proprietary package this repo doesn't carry and don't generalise (rule C); the
mechanism kept is the one that transfers to any fakerphp/faker project: factories stay a column-to-
generator map, and generation logic lives in a registered provider. The source's explicit behaviour
change — a seeder no longer allows inline generation as a fallback — is kept as point 5. Written
2026-09-29.
Point 6 added 2026-09-29, mined from the same catalogue's no-fakerphp skill: unique() keeps its
drawn values on the shared Faker instance for the process, so it is safe against an unbounded generator
but throws once a bounded value space (an enum, a short vocabulary) is exhausted across the run —
Laravel's factory Sequence is the fix kept here, since it is a public framework mechanism and not
specific to the source's internal fork.
1---2name: laravel-faker-provider-extensions3description: 'Use when a factory definition(), a factory state or a seeder is about to carry generation LOGIC instead of one Faker call per attribute — string concatenation, str_pad/sprintf building a reference, random_int/Str::random/Arr::random, a hand-typed array of domain values, a case-changing wrapper around a Faker call, or a uniqueness retry loop: write a Faker Provider extension instead.'4metadata:5 source: https://skillmd.com/skills/techmefr/laravel-faker-provider-extensions6---78# laravel-faker-provider-extensions910Narrow trigger extracted from `skills/laravel-conventions` §7.47–§7.51, so a factory attribute11carrying generation logic routes here directly instead of only through the whole Laravel block.1213## When14Writing or reviewing a factory `definition()`, a factory state, or a seeder, where one attribute's15value needs more than a single generator call to produce.1617## Steps181. **A factory attribute is one Faker call.** The moment it needs logic — concatenation, a retry19 loop, a hand-typed vocabulary array, `ucfirst()`/`strtoupper()` wrapped around a call — that logic20 moves into a `Faker\Provider\Base` subclass, in the project, on the spot.212. **Register the provider once, through a service provider's `boot()`** (`$faker->addProvider(new22 ...)`), never inside the factory, the seeder, or a test's `setUp()` — registering per-call or23 per-test leaks the provider into every test that runs after the first one in the same process.243. **Keep helper methods `private`/`protected`.** Every public method on the provider becomes a25 generator (`$faker->yourMethod()`); an internal helper made public is callable, and collidable,26 the same way.274. **Check the bundled and locale `fakerphp/faker` providers before writing your own.** A value that28 only looks plausible (an unchecked digit string standing in for something with a real check digit29 or format) is a fixture that silently drifts from what the application's own validation rules30 require.315. **Seeders follow the same rule.** Falling back to an inline string when no provider covers a value32 reintroduces the problem one call site removed from the factory.336. **`unique()` on a bounded set breaks the suite, not just one test.** Faker's `unique()` modifier34 remembers every value it has drawn on the Faker instance, and factories share that instance for the35 whole process — fine against an effectively unbounded generator (`email()`, `uuid()`), but a36 bounded set (an enum, a fixed vocabulary array, a provider method with few possible outputs)37 exhausts the pool after enough factory calls across the run, and every call after that throws. Use38 Laravel's factory `Sequence` (or a plain counter passed into the provider) instead of `unique()`39 whenever the underlying value space is small.4041## Output / checkpoint42No factory or seeder attribute in the diff builds its value with anything beyond one generator call43and its modifiers (`nullable()`, a regex/format constraint) — every attribute needing logic resolves44to a provider method, registered once, and `unique()` is only used against an unbounded value space.4546## Guardrails47- This is the generation-logic half of `skills/laravel-conventions` §7's config/commands/seeders/48 factories section — read §7.47–§7.51 for the full argument and the collision risk.49- `laravel-idempotent-seeders` and `laravel-seed-new-features` cover what a seeder's rows must do;50 this skill covers what generates the values those rows carry.51- A user override ("just inline it, this is a throwaway repro") wins without argument — this is a52 default for new code, not a rule to enforce against an explicit instruction.5354## Origin55Mined from an org skill catalogue's Laravel plugin (a `custom-faker-extensions` skill and a paired56`faker-extensions` skill, shipped 2026-09-24), rewritten around the public `fakerphp/faker`57extension mechanism (`Faker\Provider\Base`, `addProvider()`) rather than the source's own internal58Faker fork — that package's kebab-cased-registry-collision and `extra.faker`-composer-key mechanics59are specific to a proprietary package this repo doesn't carry and don't generalise (rule C); the60mechanism kept is the one that transfers to any `fakerphp/faker` project: factories stay a column-to-61generator map, and generation logic lives in a registered provider. The source's explicit behaviour62change — a seeder no longer allows inline generation as a fallback — is kept as point 5. Written632026-09-29.6465Point 6 added 2026-09-29, mined from the same catalogue's `no-fakerphp` skill: `unique()` keeps its66drawn values on the shared Faker instance for the process, so it is safe against an unbounded generator67but throws once a bounded value space (an enum, a short vocabulary) is exhausted across the run —68Laravel's factory `Sequence` is the fix kept here, since it is a public framework mechanism and not69specific to the source's internal fork.