scolib/l5-repository
A Laravel package for the repository pattern, adding criteria, presenters, validators, and cache support to keep your application's data layer clean, testable, and framework-agnostic.
Architecture fit
findOrNew addition suggests the package extends or wraps Eloquent-style lookup semantics (Laravel ships firstOrNew, not findOrNew), positioning it as a convenience layer over model/repository retrieval. This is low-architectural-weight: it should not impose structural constraints on the host application.Integration feasibility
findOrNew is additive and should be opt-in; adopting it requires no migration of existing call sites unless the team chooses to standardize on it.Technical risk
findOrNew has no stated signature, return contract, or behavior on miss. Its similarity to firstOrNew invites assumptions about whether it queries by primary key, returns an unsaved instance, or throws. Undocumented semantics are the most likely source of subtle defects.Key questions
findOrNew, and how does it differ from Eloquent's firstOrNew?Stack fit
Migration path
^3.0, run the full test suite, and smoke-test any code path that performs model lookups.findOrNew deliberately — treat it as new API to be evaluated, not a drop-in replacement. Introduce it in one or two call sites behind existing tests before standardizing.Compatibility
composer.json constraint on illuminate/* before assuming it works on current Laravel.findOrNew is added via a macro or trait.Sequencing
findOrNew implementation and document its contract internally.Maintenance
findOrNew accumulates divergent behavior from Eloquent's own retrieval methods.Support
findOrNew semantics so support does not depend on reading source.Scaling
findOrNew performs a database query on miss, review it for N+1 patterns in loop contexts before broad adoption.Failure modes
findOrNew behaves differently from firstOrNew on a miss (returns null versus an unsaved instance), call sites that assume one behavior will produce null-reference errors or unintended inserts far from the call site.Ramp-up
How can I help you explore Laravel packages today?