thedoctor0/laravel-factory-generator
Laravel Factory Generator automatically creates model factories from your existing models and database schema. It inspects columns and relationships to scaffold realistic factories, saving time when testing and seeding Laravel applications.
composer require thedoctor0/laravel-factory-generator --dev
php artisan vendor:publish --provider="TheDoctor0\LaravelFactoryGenerator\FactoryGeneratorServiceProvider"
Then run the generator against a live database connection:
php artisan generate:factory
Where to look first: the README now ships a version table and modern (Laravel 8+) factory syntax examples — use these as the reference output. Confirm the generated database/factories/ files match the class-based public function definition(): array style, not the legacy $factory->define() closure style.
First use case: point it at an existing or legacy schema (or a freshly-migrated local DB) and generate factories in bulk so you can immediately write feature tests and seeders without hand-writing every definition(). Verify your Laravel/PHP version against the new README table before assuming generated code will match your project's factory conventions.
state() methods, and wire up relationships the generator can't infer. Commit the curated factories, not the raw output.--dry-run (new in 1.5.0). Use it in CI or on unfamiliar schemas to see what would be produced/overwritten before touching database/factories/. This is the safest way to run the tool in an existing codebase.state() methods (->state(UserState::Suspended)) instead of leaving raw enum samples in definition().fake()->... / fake()->unique() style). If your project still pins older Faker conventions, normalize the output or align your Faker version.Model::factory()->create() in Pest/PHPUnit tests immediately. Curate incrementally as tests surface missing columns or bad sample data.database/factories/ directory. Previously crashed if the directory didn't exist; 1.5.0 fixes this. If you're on <1.5.0, mkdir -p database/factories first, or upgrade.Model::factory() references. Always replace *_id columns with real factory relationships in definition(), and add configure()/afterCreating() where necessary.--force-style options) will clobber your hand-edited factories. Gate destructive regeneration behind --dry-run review and keep curated files in version control so diffs are visible.--dev dependency).--dry-run), cherry-pick the tables you need, and avoid dumping dozens of low-quality factories you'll never maintain.How can I help you explore Laravel packages today?