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

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

Load comments for Laravel Where In Condition

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components

Sponsors 👑

+ Add Yours
)