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.
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.
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.
colorName, company, word), you may get different output after install. fake()->getProviders() at a tinker prompt tells you the exact order.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).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/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.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.addProvider() your subclass. The classes are plain Faker providers, so this is a one-liner and survives package upgrades.getProviders() readable.How can I help you explore Laravel packages today?