Posts Learn Components Snippets Categories Tags Tools new 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

19 views

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.
<?php

Post::query()
    ->whereIn('id', [1, 2, 3])
    ->get();

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

// 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 ☕️

)