laravel/legacy-factories
Provides support for the previous generation of Laravel factories (7.x and earlier) on Laravel 8.x and above, letting existing factory code keep working after upgrading.
factory() helper; apps depending on legacy third-party packages whose service providers or tests still invoke factory(); acquisitions/inherited codebases where you need CI green before you can safely refactor.require-dev dependency. It does not ship to production, does not alter runtime behavior, and cannot affect customers. Its blast radius is limited to test and seed data. That materially lowers the approval cost of adopting it.Adopt when:
$factory->define(...)) in database/factories/.factory(Model::class)->create() and rewriting them is not on the current critical path.factory() helper.Look elsewhere / skip when:
for()/has(), asJSON(), async/queue-aware creation, state classes). This package restores only the legacy API and deliberately does not bridge to the new one; you cannot share definitions across both styles.Governance to attach at adoption: a written convention that no new legacy factories may be added (enforceable in review or lint), a tracked ticket for removal, and a rule that each touched model migrates to a class-based factory opportunistically.
For executives (one paragraph): We're behind on a supported Laravel version, which means no security patches and an increasing number of libraries we can't take. Most of the upgrade work is mechanical, but the factory syntax change is the piece that forces every test and seeder to be rewritten at the same time. Laravel publishes an official, MIT-licensed compatibility package that makes the old syntax keep working, so we can complete the upgrade now and modernize the tests on a planned schedule instead of blocking the release. It's a development-only dependency: nothing about it ships to customers or changes production behavior, and the worst case is that tests fail in CI — which we'd catch before merge. The tradeoff is a temporary period where two factory styles coexist, so we're committing to a removal date and a rule that no new legacy factories get written.
For engineering: One-line install as a dev dependency, auto-discovered, no core changes, no production code path. It restores the factory() helper and legacy closure definitions so existing tests and seeders run unchanged on Laravel 8 through 13. It is first-party and has shipped a release for every Laravel major, which is the maintenance signal that matters here. Constraints to plan around: it restores only the legacy API — no for()/has()/asJSON(), no shared definitions between old and new styles; and mixed codebases need a convention so contributors don't guess which style to use. Recommended path: install, run the full suite to confirm parity, migrate factories opportunistically as models are touched, and close out the dependency by a set date. If factory() comes back undefined, it's autoload/package-discovery, not a package bug.
How can I help you explore Laravel packages today?