- Can I use doctrine/data-fixtures with Laravel Eloquent models?
- No, this package is designed for Doctrine ORM/ODM entities only. If your Laravel app uses Eloquent, you’ll need a bridge like `laravel-doctrine/orm` or stick to Laravel’s native factories/fakers for Eloquent models.
- How do I install doctrine/data-fixtures in a Laravel project?
- Run `composer require doctrine/data-fixtures`. Ensure you also have `doctrine/orm` or `doctrine/odm` installed, as this package depends on them. Laravel doesn’t include Doctrine natively, so you may need to configure it via a bundle.
- What’s the best way to organize fixtures for large datasets?
- Group fixtures into logical sets (e.g., `UserFixtures`, `ProductFixtures`) and use the `Executor` class to load them in order. For large datasets, enable `PURGE_MODE_TRUNCATE` cautiously, as it can be slow. Consider dry-run mode for validation.
- Does doctrine/data-fixtures support Laravel’s DatabaseSeeder?
- No, this package doesn’t integrate directly with Laravel’s `DatabaseSeeder`. You’ll need to create a custom Artisan command or service provider to trigger fixtures via `php artisan` or your CI pipeline.
- How do I handle circular dependencies between fixtures?
- Avoid circular references by structuring fixtures hierarchically (e.g., load `User` fixtures before `Order` fixtures referencing them). If unavoidable, use lazy loading or transaction rollbacks to manage failures gracefully.
- Is doctrine/data-fixtures suitable for production data seeding?
- It’s primarily designed for development and testing. For production, use migrations or manual scripts. However, you can use dry-run mode to validate fixture logic without modifying live data.
- What’s the performance impact of purging data before loading fixtures?
- Purging (e.g., `TRUNCATE`) is fast for small datasets but can be slow for large tables. For CI/CD, consider `DELETE` mode or batch processing. Always test purge strategies in a staging environment first.
- How do I test fixtures in a Laravel CI pipeline?
- Trigger fixtures via a custom Artisan command (e.g., `php artisan db:seed-fixtures`) in your CI script. Use `PURGE_MODE_DELETE` to avoid locks, and wrap execution in transactions for rollback safety.
- Are there alternatives to doctrine/data-fixtures for Laravel?
- Yes: Laravel’s built-in factories/fakers are lighter but lack referential integrity. For hybrid setups, pair factories with this package—use fixtures for complex, related data and factories for simple models.
- What Laravel versions and PHP requirements does doctrine/data-fixtures support?
- The package requires PHP 8.1+ (post-v2.0.0) and works with any Laravel version, but you’ll need Doctrine ORM/ODM (PHP 8.1+ compatible). Laravel 9+ is recommended for seamless integration with modern PHP.