dedsec/laravel-autoseeder

Automatically generate realistic database seeders for Laravel models including relationships.

Maintainers

Package info

github.com/abdullahiqbal93/laravel-autoseeder

pkg:composer/dedsec/laravel-autoseeder

Statistics

Installs: 10

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.1.2 2025-08-29 18:06 UTC

This package is auto-updated.

Last update: 2026-03-29 01:13:30 UTC


README

Automatically generate realistic database seeders for Laravel models, including relationships.

Quick start

  1. Install (dev dependency):
composer require dedsec/laravel-autoseeder --dev
  1. (Optional) Publish config:
php artisan vendor:publish --provider="Dedsec\\LaravelAutoSeeder\\AutoSeederServiceProvider" --tag=config
  1. Generate seeders:
php artisan make:auto-seeders
  1. Run seeders:
php artisan db:seed

Requirements

  • PHP: >= 7.4
  • Laravel: >= 8.0
  • Supported DB: MySQL, PostgreSQL, SQLite, SQL Server

Usage & options

Run the generator (common options shown):

php artisan make:auto-seeders [--path=app/Models] [--limit=10] [--only=User,Post] [--force] [--quiet] [--verbose]

Options (summary):

  • --path — models directory (default: app/Models)
  • --limit — number of records per model (default: 10)
  • --only — comma-separated model class basenames to process (e.g. User,Post)
  • --force — overwrite existing generated seeders
  • --quiet — suppress output (useful for CI)
  • --verbose — show debug details

Examples

  • Generate seeders for all models (10 records each):
php artisan make:auto-seeders
  • Generate 5 records per model:
php artisan make:auto-seeders --limit=5
  • Generate seeders for specific models (User and Post):
php artisan make:auto-seeders --only=User,Post
  • Use a custom models directory:
php artisan make:auto-seeders --path=app/CustomModels
  • Force overwrite of any previously generated seeders:
php artisan make:auto-seeders --force

Key features

  • Automatic model discovery (scans app/Models or provided path)
  • Type-aware data generation (respect column types/lengths, including full enum support)
  • Foreign-key aware seeding and ordering
  • Relationship detection (belongsTo, hasMany, belongsToMany, morphs, etc.)
  • Unique & composite-unique constraint handling
  • Polymorphic support and two-phase seeding for circular deps

Configuration (defaults)

After publishing, edit config/autoseeder.php. example defaults:

return [
	'models_path' => 'app/Models',
	'records_limit' => 10,
	'skip_tables' => [],
	'date_format' => 'Y-m-d H:i:s',
	'string_max_length' => 255,
	'enable_strict_types' => true,
	'enable_relationship_validation' => true,
	'enable_uniqueness_guards' => true,
];

Troubleshooting

  • "No Eloquent models found" — ensure models are in the path or pass --path.
  • "Table doesn't exist" — run php artisan migrate first.
  • Foreign key / unique constraint errors — confirm relationships and migration state.

For verbose debug output use:

php artisan make:auto-seeders --verbose

Best practices

  • Use this package in development and testing only.
  • Consider committing generated seeders if they are part of test fixtures.
  • Generate related models together to preserve referential integrity.
  • Use --only and reasonable limits when working with large schemas.

License

MIT