This is my table structure
users
id username password
orders
id user_id
order_details
id product_id order_id
And the relationship is all set
User.php
function orders() {
return $this->hasMany('Order');
}
Order.php
function details() {
return $this->hasMany('OrderDetail');
}
OrderDetail.php
I got user id and product id, I want to check if the user bought this product
User::find($userId)->orders()->details()->where('product_id', $productId)->count()
will be wrong, because orders return more than one data, how to do the check?