dimanche 18 décembre 2016

Newest items and GROUP By with Eloquent

I have the following prices-table:

shop_id (int)
product_id (int)
price (float)
created (DateTime)

Every hour a cronjob checks the shops and inserts new entries (current prices) into these price-table.

Now I want to display the newest price for a product. I have to GROUP BY the shop_id because I only want one price per shop but I only want the newest entry (created).

Can I solve this with Eloquent Query-Builder or do I have to use raw SQL? Is it possible to pass the result of a raw SQL-query into a model if the columns are the same?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire