
laravel-seeder-organization
by tanaka-mambinge
SKILL.md
name: laravel-seeder-organization description: Document how to group Laravel seeders between local and shared environments, ensure seeders guard against duplication, and keep reruns safe. license: MIT compatibility:
- opencode
- claude
- antigravity
- copilot metadata: audience: developers
Overview
Seeders in this repo should respect an environment split: shared seeders that apply everywhere and local-only helpers that run when app()->environment('local') is true. DatabaseSeeder already models that flow, so a skill can walk through adding new seeders following the same guardrails.
Directory Layout
database/seeders/– entry pointDatabaseSeeder.phpplus environment-neutral seeders.database/seeders/Dummy/– local-only helpers (e.g.,LocalUserSeeder,HistoricalInvoiceSeeder) that require development data.
Implementation Steps
- Seed shared data: write a seeder in
database/seedersand register it inDatabaseSeeder::run. UsefirstOrCreate,updateOrCreate, orupsertso repeated runs reconcile data without duplication. - Keep local helpers separate: place dev-only seeders in a
Dummysubnamespace (or equivalent) and invoke them insideif (app()->environment('local'))so they never hit staging/production. - Structure DatabaseSeeder clearly: call shared seeders in one block, then wrap the local-only calls in the environment guard, avoiding duplicate registrations (e.g., do not list the same seeder twice).
Examples
DatabaseSeeder layout
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
public function run(): void
{
$this->call([
SharedUserSeeder::class,
PolicyStatusTableSeeder::class,
]);
if (app()->environment('local')) {
$this->call([
Dummy\ProductSeeder::class,
]);
}
}
}
Shared seeder (idempotent users)
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use App\Models\User;
use Illuminate\Support\Facades\Hash;
class SharedUserSeeder extends Seeder
{
public function run(): void
{
collect([
['email' => 'dev@mugonat.com', 'name' => 'Dev Lead', 'role' => 'owner'],
['email' => 'ops@mugonat.com', 'name' => 'Ops Specialist', 'role' => 'ops'],
])->each(fn (array $payload) =>
User::updateOrCreate(
['email' => $payload['email']],
[
'name' => $payload['name'],
'password' => Hash::make('secure-password'),
'role' => $payload['role'],
]
)
);
}
}
Local-only seeder (products)
namespace Database\Seeders\Dummy;
use Illuminate\Database\Seeder;
use App\Models\Product;
class ProductSeeder extends Seeder
{
public function run(): void
{
collect([
['sku' => 'loc-prod-001', 'name' => 'Demo Policy Product', 'price_cents' => 15000],
['sku' => 'loc-prod-002', 'name' => 'Practice Claim Product', 'price_cents' => 9000],
])->each(fn (array $payload) =>
Product::updateOrCreate(['sku' => $payload['sku']], $payload)
);
}
}
スコア
総合スコア
リポジトリの品質指標に基づく評価
SKILL.mdファイルが含まれている
ライセンスが設定されている
100文字以上の説明がある
GitHub Stars 100以上
3ヶ月以内に更新がある
10回以上フォークされている
オープンIssueが50未満
プログラミング言語が設定されている
1つ以上のタグが設定されている
レビュー
レビュー機能は近日公開予定です