Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ashoor's avatar

add to query result to anothor

Hi, I want to query something like this

$v1 = Model::where('x',1)->inRandomOrder()->limit(2)->get(); $v2 = Model::where('x',2)->inRandomOrder()->limit(4)->get(); how to add the result of v1 & v2 in one object $v= $v1+$v2;

how can i do that ? thanks

edit.., I wasn't clear. I want to choose randomly 5 or 3 or 10 users who have a higher score... my approach to solving it, first groupby the score and count them then sort them desc then do foreach on the result , then check if the higher score >= 5 then queries the 5 randomly. if less than five query them and save them in a variable, then check the next score and save them in another variable and continue the foreach until getting 5 users. finally, add them in 1 variable .. I don't how I add them in one variable...sorry my English is not good

0 likes
5 replies
ashoor's avatar

@MichalOravec Thanks the problem i dont know how many queres i need to query i want to get 5 winners randomly and another time 3 and maybe 10

ashoor's avatar

@MichalOravec sorry, I wasn't clear. I want to choose randomly 5 or 3 or 10 users who have a higher score... my approach to solving it, first groupby the score and count them then sort them desc then do foreach on the result , then check if the higher score >= 5 then queries the 5 randomly. if less than five query them and save them in a variable, then check the next score and save them in another variable and continue the foreach until getting 5 users. finally, add them in 1 variable .. I don't how I add them in one variable...sorry my English is not good

ashoor's avatar

for example, I need the name of 3 winners. 1 user got 10/10fullmark, 1 user got 9/10, 5 users got 8/10.. I want to choose first , a second user and the 3rd randomly form user got 8/10

Please or to participate in this conversation.