rackbeat/laravel-morph-where-has
whereHas() fails on polymorphic (morphTo) relationships, a common pain point in multi-model systems (e.g., invoices, orders, or media with shared owners).morphTo logic.Post::morphTo('author'), Invoice::morphTo('owner')) where filtering related models via whereHas is essential for performance or business logic.morphTo relationships without deprecating them; requires explicit opt-in via new method names (e.g., customer() instead of owner()).forClass(App\Customer::class)). Missed classes will break whereHas for those types.OR conditions for each morphed class, which could impact performance on large datasets or complex queries.whereHas, custom accessors, or dynamic morph maps).morphTo relationship in your system? High diversity increases maintenance burden.whereHas be used in nested queries or joins? Performance may degrade with many morphed classes.whereHas on morphs?morphTo relationships in your codebase.whereHas is critical (e.g., filtering invoices by customer type).Invoice::whereHas('owner') with Invoice::whereHas('customer') for App\Customer morphed owners.DB::enableQueryLog()).whereHas.composer.json.morphTo (e.g., custom constraints, polymorphic keys), test compatibility.composer require rackbeat/laravel-morph-where-has
customer(), vendor()).public function customer() {
return $this->morphTo('owner')->forClass(App\Customer::class);
}
whereHas('owner') with whereHas('customer') where applicable.whereHas('customer') instead of whereHas('owner') for polymorphic filtering").DB::enableQueryLog()) to diagnose.owner_type).whereHas is used in high-traffic endpoints.whereHas for that type. Add runtime checks or tests.whereHas queries with varied data.whereHas.whereHas('customer')."How can I help you explore Laravel packages today?