Regarding Scope Queries, is it intended behavior that returning any falsey
value will result in an Eloquent\Builder
being returned?
If I return any non-falsey
value (say a number, string, array, etc) it will return the actual value (be it a number, string, array, etc) but if I return false, 0, null it always returns an Eloquent\Builder.
Is there a way to work around this, and return the correct type when a falsey
instead of a object of type builder?
Abstracted Test Case
In Model
class MyModel extends Eloquent
{
public function scopeTestFalse{
return 0;
}
public function scopeTestTrue()
{
return 99;
}
}
In Route
var_dump(MyModel::scopeTestFalse()); // object(Illuminate\Database\Eloquent\Builder)
var_dump(MyModel::scopeTestTrue()); // int(99)
static
? the above example works fine for me, using laravel 4.1 on PHP 5.3.27 – cecilozaurint(0)
the other one returnsint(99)
, make sure to declare all functions static because Eloquent implements the __callStatic() function (which gets triggered whenever you try and access a static method that's not part of the class you are calling). Hope this makes sense. – cecilozaur