Iseed
Iseed stats
- Downloads
- 5.1M
- Stars
- 2,635
- Open Issues
- 75
- Forks
- 367
Generate a new Laravel database seed file based on data from the existing database table.
Inverse Seed Generator (iSeed)
The Inverse Seed Generator (iSeed) is a Laravel package designed to efficiently generate seed files from existing database tables. This tool is ideal for developers who need to replicate database contents in a structured and reusable way, particularly useful in testing and staging environments.
Key Features
- Generate Seed Files: Automatically creates seed files based on existing database tables.
- Custom Class Names: Supports prefixes and suffixes for Seeder class names to avoid overwriting existing seeds.
- Flexible Usage: Allows specification of multiple tables, custom DB connections, chunk sizes, max rows, and more.
- Artisan Support: Fully integrated with Laravel's Artisan command-line tool, enhancing its functionality.
- Event Hooks: Provides options to execute Laravel events before and after seed generation.
Installation and Setup
-
Install via Composer:
composer require orangehill/iseedFor Laravel 5.3.7 and below or Laravel 4, specify the version:
composer require orangehill/iseed:2.2 # For Laravel 5.3.7 and belowcomposer require orangehill/iseed:1.1 # For Laravel 4 -
Register Service Provider (For Laravel 5.4 and below as newer versions support auto-discovery):
Orangehill\Iseed\IseedServiceProvider::class,
Usage
To generate a seed file for a database table:
php artisan iseed my_table
This command will create a new seed file in the /database/seeds directory with the SQL data from my_table.
Advanced Options
- Multiple Tables:
php artisan iseed table1,table2 - Overwrite Existing Seeds:
--force - Limit Rows:
--max=10 - Custom DB Connection:
--database=custom_connection - Exclude Columns:
--exclude=id,created_at
Practical Examples
Generate seeds with custom class names:
php artisan iseed users --classnameprefix=Custom
Exclude specific columns and limit the number of rows:
php artisan iseed users --exclude=email,created_at --max=50
Conclusion
iSeed is a powerful tool for Laravel developers, simplifying the process of generating seed files from existing databases, making it easier to manage and replicate database states across different environments. Whether you're working on a small project or a large enterprise application, iSeed offers the flexibility and efficiency needed for effective database management and testing.