whereNull vs where('column', null) So in mysql a null column comparison like column = NULL will never return true. How about when you are using eloquent? Is ->whereNull('column') equivalent to doing ->where('column', null)?
They are not the same.
whereNull('column')
translates to
where column is null
where('column', null)
translates to
where column = null
According to the mysql documentation (http://dev.mysql.com/doc/refman/5.7/en/working-with-null.html)
You cannot use arithmetic comparison operators such as =, <, or <> to test for NULL.
Maybe this has changed in Laravl 5.6, but
where('column', '=' ,null);
actually resolves to
where column is null
and thus both are the same.
@PierreZA can confirm from laravel "^8.40"
/**
* Set a "where" constraint on the query.
*
* @param \Closure|string $column
* @param array|string|int|null $value
* @return $this
*/
public function where($column, $value = null)
{
if (is_array($value)) {
return $this->whereIn($column, $value);
}
if ($column instanceof Closure) {
return $this->using($column);
}
if (is_null($value)) {
return $this->whereNull($column);
}
$this->wheres[] = compact('column', 'value');
return $this;
}
Please sign in or create an account to participate in this conversation.