You can use whereIn.
Oct 12, 2019
9
Level 13
Shorter version of this query
$query->whereNotIn('id',
Animal::where([category' => 'animal', 'type' => 'dog'])
->orWhere(['category' => 'animal', 'type'=>'bear'])->pluck('animal_id')->all()
)->orWhereIn('id', Animal::where(
['category' => 'animal', 'type' => 'cat']
)->pluck('animal_id')->all())
->get();
Say i have House and Animal model and having five type of animal 'Cat','Bear','Dog','Eagle','Scorpion' in House Model i want to grab only cat and rest except dog and bear (in feature i will add more), This query works but i think it so long.
Level 122
Animal::where('category', 'animal')
->wherein('type' ,[ 'dog','bear'])
->get()
1 like
Please or to participate in this conversation.