- How do I install spatie/laravel-superseeder in a Laravel project?
- Run `composer require spatie/laravel-superseeder` in your project directory. The package integrates automatically via Laravel’s service provider system, requiring no manual configuration unless you need custom behavior.
- Can SuperSeeder handle complex relationships between Eloquent models (e.g., one-to-many, polymorphic)?
- Yes, SuperSeeder supports nested relationships by defining dependencies in your YAML/JSON files. Use the `depends_on` key to specify model hierarchies, ensuring parent records are created before child records.
- Does SuperSeeder work with Laravel 9 or 10? Are there breaking changes?
- SuperSeeder is actively maintained for Laravel 8+, including 9 and 10. Spatie follows Laravel’s upgrade policy, so minor version bumps typically require no changes, but always check the [release notes](https://github.com/spatie/laravel-superseeder/releases) for specifics.
- How do I generate fake data for Eloquent models using Faker?
- Use Faker syntax directly in your YAML/JSON seed files. For example, `{{ fake('name') }}` or `{{ fake('email') }}`. SuperSeeder integrates with Spatie’s Faker package, supporting all standard Faker methods out of the box.
- What’s the best way to reset or roll back seeded data between tests?
- Use `php artisan db:seed --force` to overwrite existing data. For atomic rollbacks, wrap seeds in transactions manually or use Laravel’s `DB::transaction()` in a custom seeder class. Avoid hard deletes if using SoftDeletes.
- Can I use SuperSeeder for production-like staging environments?
- Yes, but exercise caution with large datasets. SuperSeeder is ideal for staging if you pre-validate data integrity (e.g., foreign keys) and monitor performance. Avoid sensitive data by using masked placeholders or environment-specific seed files.
- How does SuperSeeder handle duplicate records or upsert logic?
- By default, SuperSeeder overwrites existing records. For upsert behavior, use Eloquent’s `updateOrCreate` in a custom seeder class or pre-process data to avoid conflicts. Add unique constraints to your models for safety.
- Are there performance issues with large seed files (e.g., 100K+ records)?
- Yes, parsing large YAML/JSON files and instantiating Eloquent models can be slow. For production-like datasets, consider chunking seeds or using raw SQL scripts. Benchmark with `php artisan db:seed --class=SuperSeeder --verbose` to identify bottlenecks.
- How do I integrate SuperSeeder into a CI/CD pipeline (e.g., GitHub Actions)?
- Trigger seeds via `php artisan db:seed --class=SuperSeeder` in your pipeline. For parallel jobs, use `--env=testing` to avoid race conditions. Cache seed files or use Git LFS for large datasets to speed up builds.
- What alternatives to SuperSeeder exist, and when should I choose them?
- Laravel’s built-in `DatabaseSeeder` is simpler but lacks YAML/JSON support. For raw SQL, use `DB::statement()` or `laravel-shift/database-seeder`. Choose SuperSeeder if you need structured config files, Faker integration, or complex relationships. Avoid it for non-Eloquent data or projects requiring strict transaction control.