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.
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.
Post::whenOnRelation('comments', fn ($q) => $q->latest())->get();
How can I help you explore Laravel packages today?