You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support for Factories to Generate Random Data (similar to Laravel legacy factories)
#1132
When working with spatie/laravel-data, creating test data or fake objects often requires manually instantiating Data objects and filling every field. This becomes repetitive and noisy, especially for:
Feature tests
Seeder-like scenarios
Generating mock data for local development
In Laravel, legacy factories (and current model factories) solve this problem very well by providing a clean, expressive way to generate random data with overrides and states.
Having a similar concept for Data objects would greatly improve developer experience.
Proposed Solution
Add first-class support for Data Generators, inspired by Laravel’s legacy factories and current model factories.
Example API (illustrative):
UserData::generator()->make();
Factories would define default random values using Faker:
Optional integration with existing Laravel Faker instance
Clear separation between Data factories and Eloquent model factories
Thanks for the amazing work on laravel-data. This feature could make it even more powerful and enjoyable to use, especially in tests and development environments 🙌
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Problem / Motivation
When working with
spatie/laravel-data, creating test data or fake objects often requires manually instantiating Data objects and filling every field. This becomes repetitive and noisy, especially for:In Laravel, legacy factories (and current model factories) solve this problem very well by providing a clean, expressive way to generate random data with overrides and states.
Having a similar concept for
Dataobjects would greatly improve developer experience.Proposed Solution
Add first-class support for Data Generators, inspired by Laravel’s legacy factories and current model factories.
Example API (illustrative):
Factories would define default random values using Faker:
Factory States
Supporting states would be extremely valuable, similar to Laravel factories:
This would allow:
Additional Considerations
Ability to override attributes inline:
Compatibility with nested Data objects
Optional integration with existing Laravel Faker instance
Clear separation between Data factories and Eloquent model factories
Thanks for the amazing work on
laravel-data. This feature could make it even more powerful and enjoyable to use, especially in tests and development environments 🙌All reactions