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

Laravel Faker Provider Collection Laravel Package

mbezhanov/laravel-faker-provider-collection

A collection of custom Faker providers for Laravel that extends Faker with additional fake data generators for names, addresses, phone numbers, and other localized content, making it easy to seed realistic test data in your applications.

View on GitHub
Deep Wiki
Context7

Getting Started

Install via Composer:

composer require mbezhanov/laravel-faker-provider-collection

The package ships a service provider that Laravel's package auto-discovery will register, so there is usually no manual config/app.php edit needed on Laravel 5.5+. If you're on an older Laravel version, add MBezhanov\Faker\ProviderCollection\FakerProviderCollectionServiceProvider (check the README for the exact FQCN) to your providers array.

First place to look is the package's README on GitHub — the provider list is the whole point of the package and changes between releases. Skim the list of provider classes (person, address, color, barcode, payment, vehicle, and similar domain-specific generators) and note the method names you'll actually call, because they are not prefixed — they sit right alongside core Faker methods on the same generator.

First use case: enriching a model factory where base Faker feels thin. For example, adding a realistic product barcode, SKU, or payment card to a Product or Order factory:

// database/factories/ProductFactory.php
public function definition(): array
{
    return [
        'name'      => $this->faker->productName(),
        'barcode'   => $this->faker->ean13(),
        'color'     => $this->faker->safeColorName(),
        'price'     => $this->faker->randomFloat(2, 1, 500),
    ];
}

If $this->faker already resolves these methods without extra registration, the service provider has done its job — that's your smoke test that everything is wired correctly.

Implementation Patterns

Factory-first usage. The package's value is almost entirely realized inside model factories and seeders, where you need plausible, constrained data. Prefer $this->faker inside a Factory class over the global fake() helper, so locale and provider resolution go through the factory's generator consistently and it stays overridable in tests.

Seeder usage with explicit imports. In seeders, either resolve the container-bound generator:

$faker = app(\Faker\Generator::class);
User::factory()->count(50)->create([
    'bio' => $faker->paragraph(),
    'company' => $faker->company(),
]);

or use the fake() helper which delegates to the same instance. Mixing both is fine — they point at the same underlying generator.

Layering with state methods. Keep provider calls out of your model and controller code. Wrap them in factory state methods so tests can opt into specific shapes:

public function withBarcode(): static
{
    return $this->state(fn () => ['barcode' => $this->faker->ean13()]);
}

Combining with your own providers. Custom providers registered in AppServiceProvider::boot() via $faker->addProvider(new MyProvider($faker)) coexist with this package as long as method names don't collide. Register yours after the collection loads so you can override a method if you need to.

Locale scoping. If you need multiple locales (e.g., en_US for fixtures, de_DE for demo data), build isolated generators rather than mutating the global one:

$deFaker = \Faker\Factory::create('de_DE');
$deFaker->addProvider(new \MBezhanov\Faker\ProviderCollection\Provider\SomeProvider($deFaker));

This keeps the container-bound generator untouched for the rest of the app.

Fixture generation in tests. When you need deterministic but realistic data in feature tests, seed Faker and let the collection providers participate normally:

$this->faker->seed(1234);

Because the collection plugs into the same generator, seeding the global generator controls them too — this is the main reason to prefer the container binding over Faker\Factory::create() sprinkled around.

Gotchas and Tips

  • Method collisions are silent until they aren't. Faker resolves methods by walking its provider stack; the last-added provider wins. If a collection method shares a name with a core method (colorName, company, word), you may get different output after install. fake()->getProviders() at a tinker prompt tells you the exact order.
  • Locale coverage varies per provider. Not every collection provider has translations for every locale. Calling an untranslated method typically falls back to en_US strings rather than throwing, which means you can ship English color names into a German dataset without noticing. Spot-check non-default locales in a test.
  • fake() vs $this->faker in tests. RefreshDatabase + fake() works, but if you've swapped the generator in a test's setUp (e.g., to a seeded one), factories using $this->faker will still see the container binding — keep the swap in a bound service provider or $this->app->instance(\Faker\Generator::class, $seeded).
  • Version matters. The package is small and low-traffic (MIT, ~21 stars). Pin a version in composer.json and check the release notes for the fakerphp/faker constraint. If you're still on fzaninotto/faker, you almost certainly need an older tag.
  • Config caching. If the package exposes a config/faker-providers.php, remember php artisan config:cache bakes the provider list in — a new provider added to config won't take effect until you re-cache. This bites in CI where storage is empty but env differs.
  • Debugging missing methods. If fake()->someCollectionMethod() throws BadMethodCallException: Unknown format, the provider isn't registered for that locale — not that the package is missing. Confirm with fake()->getProviders() and check whether the class was in the locale's provider list.
  • Extension point. Rather than forking, subclass a collection provider and override the method that produces data you don't like, then addProvider() your subclass. The classes are plain Faker providers, so this is a one-liner and survives package upgrades.
  • Don't rely on it for correctness-critical data. These are fake values with realistic shapes. EAN-13s may not pass checksum validation (or may, depending on the provider) — verify before using them in anything that validates barcodes, IBANs, or card numbers downstream.
  • Cost of adding providers. The collection is pure PHP with no runtime I/O; the only cost is a handful of extra classes in the provider stack at bootstrap. If you only use one or two methods app-wide, consider registering just those providers instead of the whole collection to keep getProviders() readable.
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.
elsayed85/laravel-api-exceptions
ouhssini/laravel-demo-mode
daworks/ncloud-outbound-mailer-driver
gp247/cms
ignibyte/aic-gates
nexa-merchant/blog
novasa/laravel-language-center
opencage/geocode
adolfoholzer/parameters
livenetworks/ln-starter
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
cgv/localized-resource