I have a pretty complex query I am trying to make. To start, I have 2 models, Sale
and Order
.
I have the following query ($startTime is just a Carbon time stamp from the past). This grabs Orders from a certain time frame:
$currentProds = Order::with(['orderProducts.variant.product', 'orderProducts.product'])
->whereBetween('orders.created_at',
[Carbon::createFromTimestamp((int)$startTime), Carbon::now()])->get();
Sale
has 2 fields: id
and product_id
. Every time a product is added during a sale, a record is created with the id
of the sale and product_id
of the product.
I want to add this to the Order
query above so that it only grabs Orders that have orderProducts with a product_id
in the latest Sale
(latest id
) with the same product_id
.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire