jeudi 4 février 2021

Laravel Query: Adding a check from another table into current query

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.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2NZB26u
via IFTTT

Aucun commentaire:

Enregistrer un commentaire