christophrumpel/laravel-factories-reloaded
Laravel Factories Reloaded generates model factories from your existing database schema. It inspects tables and column types, then creates ready-to-use factory definitions with appropriate fake data, helping you skip manual boilerplate and start testing faster.
composer require christophrumpel/laravel-factories-reloaded:^3.0 --dev. v3.0.0 is a major bump that adds PHP 8 support, so check your php constraint first — if you're still on PHP 7.x you must stay on the v2 line. The service provider is auto-discovered; on older Laravel versions without discovery, register ChristophRumpel\LaravelFactoriesReloaded\LaravelFactoriesReloadedServiceProvider in config/app.php.php artisan vendor:publish --provider="ChristophRumpel\LaravelFactoriesReloaded\LaravelFactoriesReloadedServiceProvider") and read it once — it controls the namespace and path where factories are generated, which is the thing you'll most often need to change later.php artisan list (the package registers a make:factory-style command). Generate your first factory for a small model, e.g. User.BaseFactory, exposes $this->faker, and expects you to implement definition(): array plus point it at a model class.$factory->define(User::class, ...) into definition(), then in a test replace factory(User::class)->create() with UserFactory::new()->create(). That one-file migration tells you everything about whether the package fits your codebase.definition() using $this->faker for fake values. This is a straight port of an old closure body, and for simple factories it's the whole feature.$this->state([...]) and return $this. Usage becomes UserFactory::new()->asAdmin()->create(), which is self-documenting, IDE-discoverable, and greppable.definition() (e.g. 'user_id' => UserFactory::new()). On create() this resolves to a persisted parent; on make() you get an unsaved instance. This nested-resolution behavior is the main reason teams reached for this package over closures.->times(n) for bulk creation in seeders/tests, and ->raw() when you need the attribute array without touching the database — handy for building JSON payloads or asserting on request bodies.$this->actingAs(UserFactory::new()->create()). For seeders, combine times() with state methods (UserFactory::new()->asAdmin()->times(3)->create()).create()/make() to merge on top of definition(). Combine state first, then overrides — that ordering matches developer intuition and makes intent clear.BaseFactory (or add a project-level AppFactory extending it) for cross-cutting needs like tenant scoping, forUser() relation helpers, or timestamp overrides. Doing this per-factory creates drift fast.composer why-not / resolution against your target framework before committing. Treat it as a legacy-maintenance tool, not a greenfield choice.^2.0, PHP 8 apps can move to ^3.0, and because it's a major tag you should expect the usual composer constraint churn rather than a drop-in composer update. Budget a CI run, not a code review.factory(Model::class), converting piecemeal leaves two parallel DSLs in one repo. Pick one per project (or per domain) and finish the migration.$this->faker, not fake(). This is the most common muscle-memory miss for anyone arriving from Laravel 8+, and the resulting error ("call to undefined function fake()" or a null property) is not always obvious.$this. Forgetting the return produces a confusing failure at the next chained call rather than at the state method itself.make() vs create() with nested factories produce different object states. Leaking an unsaved nested model into a database assertion is a classic silent failure — verify with raw() and a short unit test before trusting a relationship factory.times() semantics for your pinned version, especially whether it applies to make() and raw() or only create(). Assert on the returned collection size rather than assuming — and re-run that assertion after any major bump rather than trusting it carried over.make:factory calls won't find the right place.UserFactory::new()->raw() shows the fully resolved attribute array including nested factories — much faster than reading a stack trace from a failed create().composer.json for legacy apps — now explicitly across the ^2/^3 boundary. On an unmaintained package, a stray minor bump can shift resolution behavior in ways that only show up in slow CI failures.How can I help you explore Laravel packages today?