fidum/laravel-eloquent-morph-to-one
Adds a MorphToOne relationship to Laravel's Eloquent ORM, letting a model own a single polymorphic related record. Useful when a parent has exactly one morph child, mirroring MorphMany but returning a single model with lazy and eager loading support.
morphToOne relationship type to Eloquent — a first-class way to declare "this model has exactly one polymorphic counterpart" without hand-rolling query constraints or collapsing a morphMany into an accessor. That directly affects how we model shared attachments (comments, media, addresses, audit targets) in domain layers, and whether we accept a non-native relationship type in our schema conventions.with), whereHasMorph interaction, morph-map resolution, and existence queries. Buying keeps that edge-case maintenance off our engineers; building means owning it forever. Default recommendation: buy, unless our dependency policy restricts single-maintainer packages.Consider it when:
morphMany + ->first() accessor.with, has, whereHas) for those associations and don't want to hand-write the constraints each time.Look elsewhere (or build in-house) when:
morphOne or morphTo without awkwardness — if native works, native wins; no reason to add a dependency for parity.For executives (30 seconds): A small, free open-source library we use for one specific pattern in our data model — models that point to exactly one polymorphic related record. Version 2.6.0 is a compatibility update so it keeps working on the newest Laravel and PHP releases. No breaking changes, no new behaviour, no cost, and no user-visible impact. The decision it informs is whether we standardize on this pattern in our models, and it's a low-risk yes: the package is easy to remove and doesn't touch our infrastructure. The one caveat worth noting is that it's maintained by a single developer, so we treat it as a convenience dependency, not a critical one, and we have a fallback if it's ever abandoned.
For engineering: 2.6.0 adds Laravel 13.x and PHP 8.5 support with no API changes — a pure compatibility bump, so upgrading is safe and non-urgent unless we're moving to Laravel 13. Value proposition is ergonomic: a declarative one-to-one polymorphic relationship with correct eager-loading and query-builder behaviour, instead of a morphMany + accessor or a hand-scoped query. It's a small, single-maintainer package, so pin the minor version, cover our usages with a relationship test, and record it in the dependency inventory with an owner and a replace-or-fork path. Adoption should be a shared convention decision, not a per-team choice — mixing native morphOne and morphToOne for the same conceptual pattern will confuse new joiners.
How can I help you explore Laravel packages today?