Home / Snippets / Laravel Where In Condition
Laravel Where In Condition cover

Laravel Where In Condition

173

2 years ago

0 comments

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

notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this