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 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

laravel-when-on-relation adds a fluent whenOnRelation() macro to Eloquent, letting you conditionally apply query constraints based on the relation a model was loaded through. This keeps eager-loading logic expressive and avoids brittle if checks or duplicated queries when the same model is fetched from different relations.

  • Conditionally apply clauses only when loaded via a given relation
  • Chainable, fluent API that fits naturally into existing query builders
  • Supports nested relation paths and callback constraints
  • Reduces duplicated query logic across controllers and repositories
  • Fully tested and PSR-4 compliant for Laravel 9+
Post::whenOnRelation('comments', fn ($q) => $q->latest())->get();
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.
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings
kda/laravel-package
kda/filament-dynamic-navigation
bypersoft/signbox
pairus/product-data
fayne/laravel-filament-cms-core
nodisrupt/laravel-agent
sierratecnologia/media-manager