oluokunkabiru / auto-seeder
Intelligent automated PHP database seeder for Laravel that introspects schema architectures to instantly populate precise Fake data natively adhering to Types, ENUM fields, and Foreign Key Constraints.
Requires
- php: >=8.0
- fakerphp/faker: ^1.23
- livewire/livewire: ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.0
README
A zero-config PHP package that connects to your database via an Eloquent model (or a raw PDO connection), reads all column definitions, and inserts randomly-generated, realistic data — no seeders to write by hand.
Requirements
- PHP >= 8.0
- fakerphp/faker ^1.23
Installation
composer require oluokunkabiru/auto-seeder
Artisan Command
After installation the seed:auto command is automatically available:
# Seed 1 row (default) php artisan seed:auto User # Seed N rows php artisan seed:auto User 50 # Full FQCN php artisan seed:auto "App\Models\Order" 100 # Override email domain and phone country code at runtime php artisan seed:auto User 50 --domain=acme.com --country-code=+234 # Skip specific columns php artisan seed:auto User 50 --skip=api_token,stripe_id # Use a different Faker locale php artisan seed:auto User 50 --locale=fr_FR
Web Dashboard
A self-contained browser UI is registered at http://your-app.test/auto-seeder.
Features:
- 🃏 Model cards — auto-discovered from
app/Models, each with a row count input (default 1) and a Seed button - ⚙️ Settings tab — configure locale, default count, email domain, phone country code — saved to
.env - 🌙 Dark / Light mode toggle (persisted in
localStorage) - ✅ Toast notifications on success or error
Publish the views to customise the dashboard:
php artisan vendor:publish --tag=auto-seeder-views
Disable the dashboard (e.g. in production):
AUTO_SEEDER_DASHBOARD=false
Restrict to authenticated users:
// config/auto-seeder.php 'route_middleware' => ['web', 'auth'],
The ServiceProvider is automatically registered via package auto-discovery.
Publish the config file to customise generation defaults:
php artisan vendor:publish --tag=auto-seeder-config
This creates config/auto-seeder.php in your Laravel project:
return [ // Faker locale (see https://fakerphp.org/locales/) 'locale' => env('AUTO_SEEDER_LOCALE', 'en_US'), // Default row count when seed() is called with no argument 'default_count' => env('AUTO_SEEDER_DEFAULT_COUNT', 1), // Per-column format options (exact or partial name match) 'columns' => [ 'email' => ['domain' => env('AUTO_SEEDER_EMAIL_DOMAIN', null)], // e.g. 'koadit.com' 'phone' => ['country_code' => env('AUTO_SEEDER_PHONE_COUNTRY_CODE', null)], // e.g. '+234' // 08130584550 'mobile' => ['country_code' => env('AUTO_SEEDER_PHONE_COUNTRY_CODE', null)], ], // Extra columns to always skip (on top of id, timestamps, etc.) 'skip' => [ // 'two_factor_secret', ], // Override how specific DB types are treated (future use) 'types' => [], ];
You can also use .env shortcuts without touching the config file:
AUTO_SEEDER_LOCALE=fr_FR AUTO_SEEDER_DEFAULT_COUNT=10 AUTO_SEEDER_EMAIL_DOMAIN=koadit.com AUTO_SEEDER_PHONE_COUNTRY_CODE=+234
Usage
Laravel / Eloquent
use Oluokunkabiru\AutoSeeder\AutoSeeder; use App\Models\User; // Seed 1 row (default) AutoSeeder::fromModel(User::class)->seed(); // Seed 50 rows AutoSeeder::fromModel(User::class)->seed(50); // Shorthand — pass count as second argument to fromModel() AutoSeeder::fromModel(User::class, 50); // Skip extra columns AutoSeeder::fromModel(User::class) ->skip(['api_token', 'two_factor_secret']) ->seed(100); // Custom email domain + phone country code AutoSeeder::fromModel(User::class) ->configure([ 'email' => ['domain' => 'acme.com'], // → someone@acme.com 'phone' => ['country_code' => '+234'], // → +234XXXXXXXXXX ]) ->seed(50); // Multiple phone columns with different country codes AutoSeeder::fromModel(User::class) ->configure([ 'email' => ['domain' => 'company.io'], 'phone' => ['country_code' => '+1'], 'mobile_number' => ['country_code' => '+44'], ]) ->seed(20);
Inside DatabaseSeeder.php:
public function run(): void { AutoSeeder::fromModel(\App\Models\User::class)->seed(20); AutoSeeder::fromModel(\App\Models\Product::class)->seed(100); }
Standalone PHP (raw PDO)
use Oluokunkabiru\AutoSeeder\AutoSeeder; $pdo = new PDO('mysql:host=localhost;dbname=mydb', 'root', ''); // Seed 10 rows into the "orders" table AutoSeeder::fromPdo($pdo)->seed(10, 'orders'); // Seed 1 row (default) AutoSeeder::fromPdo($pdo)->seed(table: 'orders');
How It Works
- Inspect — Reads every column from the table using
DESCRIBE(MySQL),PRAGMA table_info(SQLite), orinformation_schema(PostgreSQL). - Generate — Maps each column to a Faker method using:
- Name heuristics — e.g. a column named
email→$faker->safeEmail(),phone→$faker->phoneNumber(). - Type mapping — e.g.
decimal→$faker->randomFloat(2),datetime→$faker->dateTime(),enum('a','b')→ random pick.
- Name heuristics — e.g. a column named
- Insert — Bulk-inserts all rows via a prepared PDO statement.
Skipped Columns (automatic)
The following columns are never seeded (auto-detected):
| Column | Reason |
|---|---|
id |
Auto-increment PK |
created_at / updated_at |
Managed by ORM |
deleted_at |
Soft delete |
remember_token, email_verified_at |
Framework internals |
Supported Column Types
| DB Type | Generated Value |
|---|---|
varchar, char |
Random word/sentence |
text, longtext |
Paragraph |
int, bigint, etc. |
Random number |
tinyint(1) / boolean |
true / false |
decimal, float, double |
Random float |
date |
Random date |
datetime, timestamp |
Random datetime |
enum |
Random pick from enum values |
json |
{"key": "...", "value": "..."} |
uuid |
UUID v4 |
Supported Databases
- ✅ MySQL / MariaDB
- ✅ SQLite
- ✅ PostgreSQL
License
MIT © OLUOKUN KABIRU ADESINA