Posts Learn Components Snippets Categories Tags Tools About

Laravel Where In Condition

Learn how to define whereIn condition from Laravel Model Eloquent and DB facade the easy way

Created on Oct 26, 2021


You can write a whereIn condition to explicitly get an exact result in Laravel by passing in an array at the 2nd parameter of the method. The whereIn method verifies that a given column's value is contained within the given array and you can write the query like below.

    ->whereIn('id', [1, 2, 3])

DB::table('posts')->whereIn('id', [1, 2, 3])

// result: posts with an id of 1, 2, 3 only

Other Reads

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Laravel Where In Condition