Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - How do I select all where column is equals to x or y or z (and on..)? [duplicate]

I'm working on Laravel framework version 5.1

How do I select all of my rows from an eloquent model where his abc column equals to a or b or c?

Sorry if I haven't explained myself very well.

like image 476
Eliya Cohen Avatar asked Dec 19 '22 20:12

Eliya Cohen


1 Answers

You just chain the conditions:

App\SomeModel::where('abc', 'a')->orWhere('abc', 'b')->orWhere('abc', 'c')->get();

Or as an alternative you can use whereIn for more compact solution:

App\SomeModel::whereIn('abc', ['a', 'b', 'c'])->get();

Which checks if the value of the abc column is present in the array passed.


You can check out the Laravel documentation for more info on using Where Clauses.

like image 167
Bogdan Avatar answered May 06 '23 02:05

Bogdan