- How do I install directorytree/dummy in a Laravel project?
- Add the package via Composer: `composer require directorytree/dummy`. For Laravel testing, include `orchestra/testbench` in your `require-dev` section. The package works with Laravel 11/12 and standalone PHP projects (post-v1.1.0).
- Can I use this package for Laravel 10 or older versions?
- No, the package explicitly supports Laravel 11/12 (v1.2.0+). For older versions, check the v1.1.x branch, but compatibility isn’t guaranteed. Consider alternatives like `fakerphp/faker` if you need broader Laravel version support.
- What’s the difference between this and Laravel’s built-in Factory?
- This package offers a simpler API for generating dummy data and supports stateful factories (via `HasFactory` trait in v1.3.0+), making it easier to create complex test scenarios. Laravel’s Factory is more tightly integrated but heavier for basic use cases.
- How do I generate dummy records for a model like `User`?
- Use the factory method: `Dummy::factory(User::class)->create()`. For stateful data (e.g., admin users), chain `->state(['role' => 'admin'])` if using `HasFactory`. The package mimics Laravel’s factory pattern but with a lighter footprint.
- Does this package work with PestPHP or only PHPUnit?
- It works with both, but PestPHP support is included as a dev dependency. For PHPUnit, you’ll need `orchestra/testbench` if running Laravel-specific tests. The package itself is framework-agnostic for core functionality.
- Can I use this for production data seeding?
- No, this package is designed for development, testing, and local demos. It generates placeholder data, not production-ready fixtures. For seeding, use Laravel’s native `DatabaseSeeder` or tools like `laravel/model-factory` with caution.
- What if I need to generate nested or related dummy data (e.g., users with posts)?
- Use the `has()` method for relationships: `Dummy::factory(User::class)->has(Post::factory()->count(3))->create()`. This mirrors Laravel’s factory behavior but with the package’s lightweight API. Test with `orchestra/testbench` for assertions.
- Is there a performance impact when generating large datasets?
- The package is optimized for speed, but dynamic factories (stateful data) may add minor overhead. Benchmark against `fakerphp/faker` or Laravel’s Factory for your use case. For bulk operations, consider batching or caching generated data.
- How do I customize the dummy data format (e.g., fake names, addresses)?
- Extend the package’s `Dummy` class or use Laravel’s `Faker` integration if available. For custom formats, override the default providers or chain methods like `->withName()` if the package supports it. Check the README for provider examples.
- What are the alternatives to directorytree/dummy for Laravel?
- For Laravel-native solutions, use `laravel/model-factory` (heavier but feature-rich) or Laravel’s built-in Factory. For generic PHP, `fakerphp/faker` is more flexible. If you need mock objects, consider `mockery/mockery`. Evaluate based on your need for stateful factories or simplicity.