Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

stueynet's avatar

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)?

0 likes
4 replies
NielsNumbers's avatar

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.

1 like
mnengwa's avatar

@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;
    }
1 like

Please or to participate in this conversation.