A
A
Andrei2582022-04-01 04:21:26
Laravel
Andrei258, 2022-04-01 04:21:26

How to put many different values ​​in one laravel sql query?

I have this sql question:

foreach($id as $myid){
User::where('id', $myid)->get();
}

There are more than 100,000 values ​​in foreach and when requested, laravel takes a very long time to load or just gives a timeout.

How to do it all in one request or is there another implementation option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Elena, 2022-04-01
@Andrei258

documentation describes your case https://laravel.com/docs/9.x/queries#additional-wh...

$users = DB::table('users')->whereIn('id', [1, 2, 3])->get();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question