In Eloquent, I'd like to generate this query:
SELECT * FROM table WHERE a=1 AND ( b=2 OR c=3 );
But I seem to be generating this query instead:
SELECT * FROM table WHERE a=1 AND b=2 OR c=3;
Here is my implementation and code:
$result = Model::aIsOne()->bIsTwoOrCIsThree()->get();
Model
contains:
function scopeAIsOne($query) { return $query->where('a', 1); } function scopeBIsTwoOrCIsThree($query) { return $query->where('b', 2)->orWhere('c', 3); }
Thanks for any help. I've searched through the docs including Advanced Wheres to no avail.
You can generate parentheses by passing a callback function to where()
.
Model::where('a',1)->where(function($query) { $query->where('b', 2)->orWhere('c',3); })->get();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With