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

Laravel When On Relation Laravel Package

mashirou1234/laravel-when-on-relation

Adds a whenOnRelation helper to Laravel Eloquent so you can run callbacks or apply constraints only when a relationship is loaded or present. It keeps relation-aware models, queries, and API resources concise and free of repetitive checks.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture fit: This package is a narrow, additive extension to Eloquent's query-callback surface. whenOnRelation() provides a relation-scoped variant of Laravel's when() conditional, and the release notes explicitly state that existing when() behavior is preserved. That makes it a low-coupling utility rather than a framework replacement — architecturally low risk to adopt, and easy to remove. The main architectural question is how it extends relations: a trait on relation classes, a macro registered on Illuminate\Database\Eloquent\Relations\Relation, or a wrapper. Macro-based is the most common Laravel pattern and the least invasive, but it also means the package's behavior is coupled to framework internals.

Integration feasibility: High. The feature is opt-in, so there is no forced change to existing query-building code. Any team already using when() on Eloquent builders will recognize the pattern immediately. Integration effort is essentially one service provider registration plus targeted use sites.

Technical risk: Primarily version-maturity risk, not architectural risk. v0.1.0 signals an unstable API and thin production hardening: no evidence in the release notes of a supported Laravel version matrix, test coverage, or compatibility guarantees. The Relation class hierarchy (HasMany, BelongsTo, BelongsToMany, MorphMany, etc.) varies meaningfully across Laravel majors, and macros registered on Relation inherit or miss subclasses depending on registration approach. There is also a non-trivial naming-collision risk: if Laravel adds a similarly named helper upstream, the macro could conflict or shadow framework behavior.

Key questions:

  • Which Laravel versions are supported and tested? Is the matrix documented in CI?
  • Is the extension a trait, a macro, or a package-level wrapper? How does it handle relation subclasses?
  • How does whenOnRelation() compose with when(), unless(), and chained relation callbacks?
  • Does it return the relation instance for fluent chaining, and does it preserve the relation's query builder state?
  • What is the maintainer's support model — single maintainer, company-backed, or community? Any security reporting channel?
  • Is there a deprecation/versioning policy before 1.0?

Integration Approach

Stack fit: Fits standard Laravel applications using Eloquent relationship instances for API resources, scoped query composition, or conditional eager-loading logic. It is irrelevant for teams that build queries exclusively through repositories or the query builder without touching Relation objects — assess usage density of relations in the codebase before investing.

Migration path: Effectively zero-migration. Adoption is additive: install, register the provider (if required), and introduce whenOnRelation() at call sites opportunistically. No schema, config, or behavior changes to existing code paths. The safest pattern is to require new code to use it and leave existing when() calls untouched until there is a reason to change them.

Compatibility: The critical gating item. Because the helper targets Eloquent\Relation, compatibility must be verified against the exact Laravel major/minor versions in the fleet, including any LTS windows. Also check PHP version constraints and whether the package declares conflicts. If the application spans multiple Laravel versions across services, confirm the package supports the full range or restrict adoption to services on supported versions.

Sequencing:

  1. Version-matrix validation against the fleet's Laravel versions in a scratch branch.
  2. Contract test: verify when() behavior is genuinely unchanged and whenOnRelation() chains correctly on at least HasMany, BelongsTo, and a morph relation.
  3. Pilot in one low-blast-radius service (an internal API resource layer is a good candidate).
  4. Observe for one release cycle; then permit broader adoption via an internal coding guideline.
  5. Pin the version and revisit at 1.0.

Operational Impact

Maintenance: The code footprint is small, so maintenance burden is low if the package is macro-based and does not patch vendor internals. The real maintenance risk is pre-1.0 API churn and abandonment. Mitigation: pin exact versions, wrap usage behind a project-local helper if usage becomes widespread, and keep adoption shallow enough to unwind quickly.

Support: v0.1.0 with no stated backing in the release notes is the weakest signal. Assume no SLA. Treat this as a "convenience dependency," not infrastructure — a service that must be upgradeable independently and replaceable within a sprint. Confirm there is an issue tracker and a security contact before production use.

Scaling: Runtime cost is negligible; conditional callbacks are evaluated at query-construction time and add no meaningful query overhead. The scaling concern is cognitive and organizational: parallel, near-identical APIs (when and whenOnRelation) invite inconsistency across teams. Publish a one-paragraph rule for which to use where, or the codebase will drift.

Failure modes:

  • Silent non-application — macro not registered (provider missing, cached config, or autoload issue), so the callback never runs and no error surfaces. This is the highest-severity failure mode because conditional logic fails open.
  • Framework collision — a future Laravel release introduces a same-named method, causing a fatal redeclare or shadowing. Upgrade-path hazard.
  • Inconsistent chaining semantics — differing return types between when() and whenOnRelation() breaking fluent chains in unexpected places.
  • Version skew — a service upgrades Laravel while the package lags, leaving relation behavior divergent across services.

Ramp-up: Low for any developer fluent in Eloquent — the API mirrors an existing pattern, so training is minutes, not days. The real ramp-up cost is documentation: at v0.1.0, expect the README to be the only reference and plan to write an internal usage note with the pilot's findings. Budget roughly half a day for the pilot engineer to validate behavior, document the chaining contract, and record the version matrix.

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.
shitoudev/permissionmanager
johannesclimacus/laravel-tui
hocvt/seotools
vitalybaev/sypexgeo
amphibee/themosis-ignition
gito-me/fast-excel
frankyso/laravel-ipaymu
geolize-studio/laravel-chile
boomerangui/chat
jinas/dhivatar
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console