I'm using Laravel 4.2 Query Scopes but encountered a problem.
My Model:
class SomeModel extends Eloquent {
public function scopeS1($query) {
return $query->where('field1', '=', 'S1');
}
public function scopeS2($query) {
return $query->where('field2', '=', 'S2');
}
}
Now when I do SomeModel::s1()->s2()->get(); it returns all results and doesn't filter by S1 AND S2. Note also that I have no problem when I do
SomeModel::where('field1', '=', 'S1')->where('field2', '=', 'S2')->get()
So why is query scoping and doing anything here??
SomeModel::s1()->s2()->toSql()return?toSql()here but what should be noted is that I don't see any paranthese around operators in the SQL output, which I think explains the issue. So how can I do, for example(field1 = 'S1' OR field1 = 'any') AND field2 = 'S2'instead offield1 = 'S1' OR field1 = 'any' AND field2 = 'S2'using scopes?