How to get/find data by multiple ids in laravel

How to find data by multiple ids in laravel


In this post, we are learning about how to get or retrieve data by multiple ids in laravel.

So, lets see with different examples.


Example 1: Get data using findMany() method in laravel.

$models = Model::findMany([1, 2, 3]);


Example 2: You can also pass an array to find() and it will internally call findMany():

$models = Model::find([1, 2, 3]);


Example 3: we can use the whereIn() method to find mulitple data by specifying the column name:

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


Thank you.

© Copyright - 2018 - 2022 | All rights reserved at Funda of Web IT