user3892232
user3892232

Reputation:

Query a database filtered by array in Laravel

I have a table customer in my database:

Customer Id_customer name surname ...

And an array of id_customers:

$c = array[2,4,8,9]

I can obtain the customers like this:

$customers = Customer::all();

But, how can I obtain in Laravel just the customer contained in the array?

 $customers = Customer::all()->where(?¿?¿);

Very thanks in advance

Upvotes: 0

Views: 45

Answers (1)

Fjarlaegur
Fjarlaegur

Reputation: 1443

Try using the whereIn() method.

$users = Customer::whereIn('Id_customer', [1, 2, 3])
             ->get();

Read the docs on this here: https://laravel.com/docs/5.7/queries

Upvotes: 4

Related Questions