Let's say I have an order model with two address models, shippingAddress and billingAddress. I want to select all orders where the street_address in both shippingAddress and billingAddress are the same.
@MohamedTammam In your example, your first whereHas is on the Order model, which is correct, but your second whereHas is chained on the where statement within the whereHas on the shippingAddress model. You're trying to retrieve a billingAddress from the shippingAddress.
@MohamedTammam This is a query to retrieve many models. We want to get ALL orders that have the same street address for billing and shipping - so there is no single $order to reference from
@Tray2 shippingAddress and billingAddress are in the same table and do share parent_id, but I'm unable to add any columns to the DB. This is an older magento database that I'm building tools using laravel
@johnvoncolln I would suggest moving the application to a fresh database with a updated schea, but that takes time to do, and is hard to sell to the ppl paying for your services.
@Tray2 Thanks - the Magento site is still active and this is a temporary situation that doesn't have to be great. I've about got @kevinbui 's suggestion working, but then my computer decided to turn off
@kevinbui This almost works, but ->whereColumn('shipping_street_address', 'billing_street_address') throws it off. These fields don't exist on the main model, so it can query them
@kevinbui it says those fields don't exist. I'm thinking for this that maybe a join is better. I've actually gone a different route, but still using your suggestion of the addSelect to show the data, but have it highlighted conditionally on the view.