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

Fixtures Laravel Package

davidbadura/fixtures

Flexible PHP fixtures library with YAML/JSON/TOML/PHP loaders, Faker support, automatic dependency resolution, configurable converters, tagging/filtering, validation via events, expression language, and persisters for Doctrine ORM/MongoDB and Propel.

View on GitHub
Deep Wiki
Context7

A library to load yaml, json or php fixtures. Easy extendable, resolve object dependency and validate objects.

Frequently asked questions about Fixtures
How do I load YAML fixtures in Laravel using davidbadura/fixtures?
First, install the package via Composer (`composer require davidbadura/fixtures`). Then create a YAML file (e.g., `users.yml`) with your fixture data. Use the `FixtureManager` to load it: `$fixtureManager = new FixtureManager(); $fixtureManager->load('path/to/users.yml');`. The package automatically resolves dependencies and converts data into objects.
Does this package work with Laravel’s Eloquent models, especially nullable fields?
Yes, the package now supports nullable constructor arguments (fixed in PR #24), making it compatible with Eloquent models that have nullable fields. This resolves a common issue when seeding models with optional attributes. However, it still lacks native integration with Laravel’s Seeder lifecycle.
Can I use this for non-database fixtures like Redis or API mocks?
Absolutely. While the package excels with database fixtures (Doctrine, MongoDB, Propel), it’s also great for non-DB objects like Redis cache entries, API responses, or service layer mocks. You can create custom persisters to handle these cases. Laravel’s Factory doesn’t natively support this, making this package a strong alternative.
What Laravel versions does davidbadura/fixtures support?
The package is compatible with Laravel 5.x and 6.x, but its last major update was in 2022. Since it’s archived, ensure your Laravel version aligns with its dependencies (e.g., PHP 7.4–8.1). For Laravel 10/11, test thoroughly or fork the package to add support for newer PHP features like enums or read-only properties.
How do I handle complex dependency graphs in fixtures?
The package automatically resolves bidirectional references and circular dependencies. Define your fixtures with tags or hierarchical structures in YAML/JSON, and the `FixtureManager` will load them in the correct order. For example, a `User` fixture referencing a `Role` will load the `Role` first. This is more flexible than Laravel’s Factory for nested relationships.
Is there built-in support for Faker in Laravel?
Yes, the package integrates with [Faker](https://github.com/fzaninotto/Faker) to generate fake data dynamically. In your YAML/JSON fixtures, use Faker expressions like `{{user.name}}` or `{{faker('email')}}`. The `ExpressionLanguage` component (powered by Symfony) evaluates these during fixture loading, making it easy to create realistic test data.
How do I validate fixtures before loading them into Laravel?
Use Symfony’s Validator component via events. Define validation rules in your fixture files (e.g., `email: ~` for required fields) or extend the `Validator` class to add custom checks. The package dispatches validation events before persisting objects, ensuring data integrity. This is useful for Laravel applications where test data must match production constraints.
Can I migrate from Laravel’s DatabaseSeeder to this package?
Yes, but expect some refactoring. Convert your PHP-based seeders to YAML/JSON fixtures and replace `create()` calls with the `FixtureManager`. For example, a `User` seeder would move to `users.yml`, and dependencies (e.g., `Role`) would be resolved automatically. However, you’ll lose Laravel’s `RefreshDatabase` or `DatabaseTransactions` integration unless you build custom persisters.
What are the risks of using an archived package in Laravel production?
The package is archived with no recent activity, so risks include unpatched vulnerabilities (e.g., outdated Symfony components) or breaking changes in newer Laravel/PHP versions. For production, audit dependencies manually or fork the package to apply critical updates. Consider alternatives like `laravel-shift/database-fixtures` if long-term maintenance is a priority.
How do I filter or tag fixtures for specific Laravel test environments?
Use the `FixtureManager`'s tagging system to group fixtures (e.g., `tag: 'admin'`). Load only relevant fixtures in your Laravel tests with `$fixtureManager->load('path/to/fixtures.yml', ['tag' => 'admin'])`. This is useful for staging environments where only partial data is needed, avoiding the overhead of loading all fixtures.
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky