Laravel

Eloquent whereIn Method1 min read

The whereIn method is used to filter a query by checking if a given column’s value is contained within a given array. Here’s an example of how you might use it in a Laravel application:

This will select all users with an id of 1, 2, or 3.




You can also use the whereNotIn method to select all rows that have a column value that is not contained within a given array.

This will select all users with an id that is not 1, 2, or 3.


In Eloquent (Laravel’s ORM), the whereIn method can be used to filter a query by a given column’s values. Here’s an example:

This would return all users whose id is 1, 2, or 3.

You can also use whereNotIn to filter out results where the given column’s value is in the given array.

This would return all users whose id is NOT 1, 2, or 3.

You can also chain other constraints onto the query, like so:

This would return all users whose id is 1, 2, or 3 and whose age is greater than 18.

Leave a Comment