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.
whenOnRelation() lets teams apply constraints or eager-loading behavior conditionally on an Eloquent relation instance, reducing one-off branching in controllers, resources, and query scopes.if statements across request handlers.Consider adoption when:
when() behavior and avoids changing native query semantics.0.1.x, review the implementation, and accept early-stage API stability risk.Look elsewhere or defer when:
when() on queries or ordinary relationship constraints already cover your use cases.For executives: This is a small, low-risk Laravel convenience package that reduces repeated conditional relationship logic in application code. It is opt-in and does not alter Laravel’s default behavior, so adoption can be scoped to a pilot without platform-wide change.
For engineering: v0.1.0 adds whenOnRelation() for Eloquent relationship instances while keeping Laravel’s existing when() unchanged. It is useful for cleaning up conditional relation callbacks, but it is early-stage and narrow in scope. Recommend pinning the version, reviewing test coverage/maintenance, and piloting in one service before standardizing. Do not position it as a replacement for query filters, authorization, or API resource layers.
How can I help you explore Laravel packages today?