oluokunkabiru/auto-seeder
Composer 安装命令:
composer require --dev 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.
README 文档
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
oluokunkabiru/auto-seeder 适用场景与选型建议
oluokunkabiru/auto-seeder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「database」 「faker」 「testing」 「laravel」 「seeder」 「auto-seed」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 oluokunkabiru/auto-seeder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 oluokunkabiru/auto-seeder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 oluokunkabiru/auto-seeder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Dibi is Database Abstraction Library for PHP
Testing Suite For Lumen like Laravel does.
Store your language lines in the database, yaml or other sources
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Symfony bundle to manage fixtures with Alice and Faker.
Additional plugin for fakerphp/faker that allows you to generate a random animal
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-03