I'm trying to retrieve the latest 5 rows for each foreign key in a table, so imagine the following database structure:
CATEGORY (id, name)
ARTICLE (id, category_id, title)
I want do something like this:
Article::where("category_id", 1)
-> latest()
-> limit(5)
-> get();
Article::where("category_id", 2)
-> latest()
-> limit(5)
-> get();
And so on. How would I do this as a single query for all foreign keys?
Thanks!
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2kBUnHb
via IFTTT
Aucun commentaire:
Enregistrer un commentaire