Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Entity Faker

Entity Faker Laravel Package

butschster/entity-faker

Generate fake PHP entities and persist them via your ORM using a simple factory. Define per-class attribute generators with Faker, support inheritance via raw attributes, and create single or multiple entities using Laminas hydrators/entity factories.

View on GitHub
Deep Wiki
Context7

Create fake entities based on your classes

Frequently asked questions about Entity Faker
How do I install butschster/entity-faker in a Laravel project?
Run `composer require butschster/entity-faker` in your project directory. The package integrates seamlessly with Laravel’s Composer autoloader, so no additional configuration is needed for basic usage. Ensure your Laravel version (10+) and PHP (8.2+) meet the package’s requirements.
Does this package support Laravel Eloquent models?
Yes, the package works with Eloquent models out of the box. You can define fake data for Eloquent classes using the `define()` method and persist entities via Eloquent’s ORM. The redesign in v2.0.0 maintains compatibility but may require adjustments for complex relationships.
Can I generate fake data for inherited classes like SuperUser extending User?
Absolutely. Use the `raw()` method to inherit attributes from parent classes. For example, define `SuperUser` by extending `User`’s attributes with additional fields like `isAdmin`. The package handles inheritance via raw attribute merging, as shown in the README.
What Laravel and PHP versions does butschster/entity-faker support?
The package officially supports Laravel 10+ and PHP 8.2+. If you’re using an older version, check the changelog for compatibility notes or consider forking the package. The redesign in v2.0.0 may introduce breaking changes, so test thoroughly if upgrading from v1.x.
How do I generate multiple fake entities at once?
Use the `createMany()` method to generate bulk entities. For example, `$factory->of(User::class)->createMany(10)` will produce 10 fake `User` instances. This is useful for seeding databases or testing large datasets efficiently.
Does the package support relationships like hasMany or belongsTo?
Yes, but relationship handling may require explicit configuration in v2.0.0. The redesign simplifies customization, so you can define relationships using closures or arrays. Test polymorphic, many-to-many, and pivot attributes to ensure they work as expected in your Laravel models.
How can I ensure deterministic fake data for testing?
The package doesn’t natively support seeding like Laravel’s factories, but you can achieve determinism by passing a fixed seed to Faker (e.g., `Faker::create()->seed(1234)`). For reproducible tests, combine this with the package’s `raw()` method to control attribute generation.
Are there performance concerns when generating large datasets?
Generating thousands of entities may impact performance, especially with deeply nested relationships. Use transactions and chunking (e.g., `Model::chunk()`) to batch operations. Benchmark your use case, as the v2.0.0 redesign might introduce optimizations or overhead.
What alternatives exist for fake entity generation in Laravel?
Consider Laravel’s built-in `Factory` classes (e.g., `Model::factory()`) for Eloquent models, or packages like `fakerphp/faker` for standalone fake data. For non-Eloquent classes, `mockery/mockery` or `phpunit/phpunit` with data providers are alternatives. Choose based on your need for inheritance, customization, or ORM integration.
How do I migrate from v1.x to v2.0.0 of butschster/entity-faker?
Review the changelog for breaking changes, such as renamed classes (e.g., `EntityFaker` → `EntityFactory`). Update your code to use the new API, especially for defining entities and handling relationships. Test incrementally with critical models, and consider a wrapper layer if migration is too disruptive.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle