Description
Sometimes, I have to use this syntax :
User::whereRaw(array('programs_ids.'.$program_id => array('$exists' => true)));
It could be better if it was :
User::whereExists('programs_ids.'.$program_id);
But a whereExists()
method already exists in Laravel. It corresponds to the WHERE EXISTS
SQL operator, wich have no sens in the MongodDB context, am I right ? It could be good to overwrite the initial method with an other one, matching the $exists
MongoDB operator like in the case above but it's impossible because the arguments are not the same (the initial method need a Closure as first argument).
We could have a whereFieldExists()
method with an implementation like that :
public function whereFieldExists($column, $exists = true, $boolean = 'and')
{
return $this->whereRaw(array($column => array('$exists' => $exists)), array(), $boolean);
}
public function whereFieldNotExists($column, $boolean = 'and')
{
return $this->whereFieldExists($column, false, $boolean);
}
After tests and writing this I'm not completely sure that this syntax is really great... What do you think about ? this question is more general because we could have also whereType
or whereAll
. I could work on this in the next days.