- How do I install nelmio/alice in a Laravel project?
- Run `composer require nelmio/alice` in your project directory. Alice integrates seamlessly with Laravel and requires no additional configuration beyond FakerPHP, which it uses under the hood. For Laravel-specific setup, follow the framework integration guide in the docs.
- Can I use Alice to generate complex nested relationships (e.g., users with posts and comments)?
- Yes, Alice excels at hierarchical data. Define relationships in YAML/JSON using references (e.g., `user: *user_1`) or lists to create nested structures like a user with multiple posts, each having comments. The package handles Eloquent relationships natively.
- Does nelmio/alice work with Laravel’s built-in factories or replace them?
- Alice supplements Laravel factories by offering declarative YAML/JSON fixtures for complex scenarios. You can use both: replace factories for hierarchical data while keeping simple models in factories. Alice also supports calling factory methods directly in fixtures.
- What Laravel versions does nelmio/alice support?
- Alice is compatible with Laravel 8.x, 9.x, and 10.x. It leverages Eloquent ORM, so it works with any Laravel version that supports Eloquent. Check the package’s [Packagist page](https://packagist.org/packages/nelmio/alice) for the latest version requirements.
- How do I generate fixtures for a specific database (e.g., PostgreSQL vs. MySQL)?
- Alice is database-agnostic and works with Eloquent, so it supports MySQL, PostgreSQL, SQLite, and others out of the box. No additional configuration is needed—just define your fixtures in YAML/JSON, and Alice will generate data compatible with your database schema.
- Can I use Alice fixtures in CI/CD pipelines (e.g., GitHub Actions) for testing?
- Absolutely. Alice fixtures are version-controlled and reproducible, making them ideal for CI/CD. Seed test databases in your pipeline using `php artisan alice:load` or integrate with PHPUnit/Pest. Pre-generate fixtures to speed up test execution.
- How do I ensure fixtures match production data distributions (e.g., 90% active users)?
- Use Alice’s fixture ranges and custom providers to control data distributions. For example, define a range like `active_users: 90%` and `admins: 10%` in your YAML. Combine this with Faker providers or custom logic to enforce constraints.
- What’s the performance impact of loading large datasets with Alice?
- For large datasets, use batch inserts with `->persist()` or wrap operations in database transactions to optimize performance. Alice also supports lazy loading, so you can generate fixtures incrementally. Test with your expected dataset size to fine-tune.
- Are there alternatives to nelmio/alice for Laravel fixture generation?
- Yes. Laravel’s built-in factories are lightweight for simple data, while packages like Laravel Snappy or Mockery focus on mocking. Alice stands out for expressive YAML/JSON fixtures with Faker integration, making it ideal for complex, reusable test data. Compare based on your need for declarative vs. programmatic generation.
- How do I migrate from Laravel factories or manual SQL dumps to nelmio/alice?
- Start by replacing one or two critical factories with Alice fixtures (e.g., users.yml). Use the `php artisan alice:generate` command to scaffold fixtures from existing data. Gradually migrate by validating outputs against your tests. The package’s modular design allows incremental adoption.