Support the ongoing development of Laravel.io →
Eloquent
Last updated 2 years ago.
0

LostMyUnicorn said:

Hi guys,

I'm using FindMany to retrieve a bunch of records from my database that matches an array of Id's.

return Product::findMany([1,1,1,1,1]);

This is returning just 1 record with the ID of 1 as you'd expect. However, I wish for it to return 5 duplicates of said record.

Is this possible?

If I understand correctly, findMany actually does this:

$models = Model::whereIn('id', [1, 1, 1, 1, 1])->get();

Which is what's getting you just one record right now. I don't think the database itself won't return duplicates in the same query.

If you want more, you might need to do each query separately. But that's not that efficient.

Alternatively, you can try getting the database query as it is (so you only have 1 record), then make a new array so that for each of your initial ID array, it matches to the result of the database query.

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.