dedsec/laravel-autoseeder
最新稳定版本:v1.1.2
Composer 安装命令:
composer require --dev dedsec/laravel-autoseeder
包简介
Automatically generate realistic database seeders for Laravel models including relationships.
README 文档
README
Automatically generate realistic database seeders for Laravel models, including relationships.
Quick start
- Install (dev dependency):
composer require dedsec/laravel-autoseeder --dev
- (Optional) Publish config:
php artisan vendor:publish --provider="Dedsec\\LaravelAutoSeeder\\AutoSeederServiceProvider" --tag=config
- Generate seeders:
php artisan make:auto-seeders
- 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/Modelsor 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 migratefirst. - 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
--onlyand reasonable limits when working with large schemas.
License
MIT
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-28