Weave 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

Eloquent Relativity Laravel Package

imanghafoori/eloquent-relativity

Laravel package that lets you declare Eloquent relationships without importing related model classes. Relativity infers the target model from the method name, so hasMany, hasOne, belongsTo and belongsToMany calls stay concise and your models keep fewer use statements.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit

  • The package replaces hard-coded model class references inside Eloquent relationship methods ($this->hasMany(Comment::class)) with string-keyed lookups ($this->relTo('comments')), resolved through a central key→class map registered in a service provider/config.
  • This is a genuine architectural tool, not a feature package: it targets modular monoliths, package-per-domain layouts, and DDD-style bounded contexts where a Billing module must not use App\Modules\Users\Models\User.
  • It also enables model substitution (multi-tenant variants, test doubles, versioned models) behind a stable relation key, which is the strongest concrete use case.
  • It is not justified for conventional CRUD apps — it adds an indirection layer with no functional payoff.

Integration feasibility

  • Installation is trivial (Composer, service provider auto-discovery, publish config). Adoption is not: every boundary-crossing relation in every model must be rewritten, so this is a codebase-wide change priced per relationship, not per package.
  • Native and relative relations can coexist on the same model, which makes incremental adoption realistic.
  • Fit is best in greenfield modules; retrofitting a mature domain model is where cost and regression risk concentrate.

Technical risk

  • Single maintainer, ~148 stars, zero dependents, last release April 2024. Bus factor is the dominant risk, not code quality.
  • The indirection defeats IDE navigation, Larastan/PHPStan return-type inference, IDE Helper generation, and any tool that reflects on relationship return types or introspects model classes (Nova, Filament, Spatie Query Builder, API-doc generators). This must be verified empirically, not assumed.
  • Key typos become runtime failures rather than compile-time or static-analysis failures — a real regression in defect-detection posture.
  • Laravel major-version compatibility is unproven beyond the current release; the package is upstream of nothing, so you are the only one who will feel a break.

Key questions

  • Which Laravel/PHP versions are covered by the test matrix, and is there CI evidence?
  • Do relative relations return native Relation instances (so with(), whereHas(), withCount(), hasManyThrough, morph relations all behave identically)?
  • How are polymorphic relations and Relation::enforceMorphMap handled — do the two mappings conflict?
  • Is the key map cached, and is it resolved once per request or per relation call?
  • What is the exit cost — how many files reference relTo, and can it be swapped for a thin internal wrapper?
  • Does the package enforce the decoupling it enables, or can developers still import classes directly? (If the latter, pair it with Deptrac/PHPArkitect.)

Integration Approach

Stack fit

  • Laravel 9/10/11 and PHP 8.1+ is the expected envelope and should be confirmed against the package's CI before commitment.
  • Best fit: modular monolith with enforced module boundaries, or a codebase already extracting domains into private Composer packages. Poor fit: single-team, single-context apps and legacy codebases mid-migration.

Migration path

  • Introduce behind a deliberate seam: wrap relTo in a project-owned trait so the vendor dependency is one file deep and replaceable.
  • Convert relations that cross module boundaries first — those carry the decoupling value. Intra-module relations should keep native Eloquent and gain nothing from indirection.
  • Both styles coexist per model, so conversion can proceed domain by domain without a big-bang release.

Compatibility

  • Verify against the specific introspection surface you actually run: admin panel resources, query-builder packages, Larastan level, IDE Helper, factories using for(), and route model binding/policy auto-discovery.
  • Polymorphic relations and any package performing instanceof checks on relation objects are the highest-probability breakpoints.

Sequencing

  1. Spike: convert one module's outbound relations, run the full tooling stack (static analysis, admin panel, test suite).
  2. Decide on key naming conventions and document them — the keys become a public contract between modules.
  3. Pilot in production on one bounded context with a rollback plan (revert to class references).
  4. Add architectural enforcement (Deptrac/PHPArkitect) so direct cross-module model imports fail CI; the package alone does not prevent them.
  5. Expand module by module; keep a live inventory of converted relations.

Operational Impact

Maintenance

  • Small runtime surface, but maintenance ownership effectively transfers to you. Pin the version, avoid contributing upstream-only patches, and budget for a fork or in-house replacement if the maintainer stops.
  • Upgrades of Laravel become a two-party negotiation (framework + this package); schedule accordingly.

Support

  • GitHub issues only. No commercial support, no SLA, small community means slow answers. Internal documentation of the key registry and conventions is mandatory, not optional.

Scaling

  • Runtime cost is negligible: one map lookup per relation resolution, and it should be cached. No impact on query count, eager loading, or horizontal scaling.
  • The scaling concern is organizational: the key map becomes a shared contract that grows with the number of modules, and its governance does not scale without conventions and ownership.

Failure modes

  • Unresolved or misspelled key → runtime exception at the point of relation use, often in production paths not covered by tests.
  • Silent static-analysis blindness → bugs that PHPStan/Larastan would have caught now ship.
  • Hidden dependency graph → changing or removing a key has non-local blast radius that grep only partially reveals.
  • Upstream abandonment or Laravel-major incompatibility → blocked framework upgrades.
  • Onboarding regression → new engineers cannot follow relations by IDE navigation and must learn the registry.

Ramp-up

  • Syntax is learnable in minutes; the architectural intent takes a session to internalize. Expect roughly a half-day of onboarding plus living documentation.
  • The real ramp-up cost is for anyone outside the team (contractors, auditors, new hires) reading the code cold, and for tooling that assumes class-based relations.

TPM verdict

  • The package solves a real problem, but the same decoupling is achievable with Model::resolveRelationUsing, container-bound interfaces, or boundary enforcement in CI without a single-maintainer dependency. Given zero dependents and a 2024 release with no visible momentum, adopt only where the modular-boundary value is concrete, behind a wrapper seam, and after tooling validation — not as a default architecture choice.
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.
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log
gregsphotography/site-builder-components
io-digital/clickatell
snowsoft/laravel-admin
oxygen/auth
relicsoftware/barakah-payment-gateway
tobya/work-with-composer
equipc/laravel-email-validator