Monday, May 22, 2017

Need to get a make a query where there is atleast one condition

I have a table like this:

Table: item
isBeautiful: Boolean
isGreat: Boolean
isAvaliable: Boolean

I want to make a query with Eloquent that gives me all the items that are avaliable and are either isBeautiful or isGreat, or both.

$avaliableitems = item::where("isAvaliable,1)
                  ->where("isBeautiful",1)
                   ->orWhere("isGreat",1)->get();

This is pseudocode, I know it doesn't work.

I know I can alwaysjust get item where isavaliable = 1 and then loop through each item and do:

foreach($avaliableitems as $avaliableitem){
if($avaliableitem->isBeautiful == 1 || $avaliableitem->isGreat){

//do things

}
}

But I wonder if there is a way to do it with Eloquent as mentioned before.



via prgrm

Advertisement