Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I do Model->where('id', ARRAY) multiple where conditions?

Tags:

php

laravel

The title says it all.

I get that I can do this :

DB::table('items')->where('something', 'value')->get() 

But what I want to check the where condition for multiple values like so:

DB::table('items')->where('something', 'array_of_value')->get() 

Is there an easy way of doing this?

like image 272
Vudew Avatar asked Jun 08 '15 10:06

Vudew


People also ask

Can we use array in where clause?

So, our using the WHERE IN clause we can fetch the rows and columns from the database table array by following and validating a condition to result required set of output table in the MySQL server.

How do I use whereBetween in Laravel?

The whereBetween() method is a query builder chained alongside other Laravel query builders used to fetch data from the database. The whereBetween() method queries the database table to fetch rows of records from the database within a range of values.

How do you pluck in Laravel?

The Laravel pluck () as the name suggests, extracts certain values, as suggested. It literally plucks the information out from the given array and produces it as an output. However, it is most effective against objectives, but will work well against arrays too.

Where IS NOT NULL eloquent?

Check if not null: whereNotNullSELECT * FROM users WHERE last_name IS NOT NULL; The equivalent to the IS NOT NULL condition in Laravel Eloquent is the whereNotNull method, which allows you to verify if a specific column's value is not NULL .


1 Answers

There's whereIn():

$items = DB::table('items')->whereIn('id', [1, 2, 3])->get(); 
like image 179
Limon Monte Avatar answered Oct 13 '22 05:10

Limon Monte