Database Seeding

Seed Laravel databases with idempotent core, reference, and development seeders.

1|Updated May 28, 2025
One-click install
npx skills add https://github.com/hackur/web-standards-playground-showcase --skill database-seeding
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: Database Seeding
Source: https://github.com/hackur/web-standards-playground-showcase/tree/main/.claude-laravel-backup/skills/database-seeding
Command: npx skills add https://github.com/hackur/web-standards-playground-showcase --skill database-seeding

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Idempotent seeder patterns with core/reference/dev separation and environment-specific execution using firstOrCreate/updateOrCreate.

Core Features & Use Cases

  • Three seeder categories: Core (Always Run), Reference (Optional), Development (Local)
  • Idempotent seeds using firstOrCreate and updateOrCreate
  • Environment-specific execution logic for development data

Quick Start

./scripts/dev.sh seed:core

Frequently Asked Questions about Database Seeding

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I make database seeders idempotent in Laravel?

Idempotent seeders use firstOrCreate and updateOrCreate methods to safely re-run without duplicating data. These Laravel methods check if a record exists before inserting or updating, allowing seeders to run multiple times across environments without errors.

How do I organize Laravel seeders for core, reference, and development data?

Separate seeders into three categories: Core seeders always run, Reference seeders run optionally for lookup tables, and Development seeders run only locally. The DatabaseSeeder orchestrates which category executes based on environment.

Can I run different seeders in different Laravel environments?

Yes, environment-specific execution logic lets you control which seeders run in development, staging, and production. The DatabaseSeeder class checks the current environment and executes only the appropriate seeder categories.

What's the best way to structure Laravel database seeders for repeated runs?

Use firstOrCreate and updateOrCreate within organized seeder classes grouped by category. This pattern ensures data consistency across repeated executions while maintaining a clear directory structure for core, reference, and development seeders.

Why should I use firstOrCreate instead of create in Laravel seeders?

firstOrCreate prevents duplicate records when seeders run multiple times by checking if data already exists. If the record exists, it returns the existing row; if not, it inserts a new one, making your seeder safe and repeatable.