{"record":{"id":"667a433c7256ad1c","repo":"laravel/framework","slug":"illegal-operator-and-value-combination","errorCode":null,"errorMessage":"Illegal operator and value combination.","messagePattern":"Illegal operator and value combination\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Database/Query/Builder.php","lineNumber":1068,"sourceCode":"        }, $boolean);\n    }\n\n    /**\n     * Prepare the value and operator for a where clause.\n     *\n     * @param  string  $value\n     * @param  string  $operator\n     * @param  bool  $useDefault\n     * @return array\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public function prepareValueAndOperator($value, $operator, $useDefault = false)\n    {\n        if ($useDefault) {\n            return [$operator, '='];\n        } elseif ($this->invalidOperatorAndValue($operator, $value)) {\n            throw new InvalidArgumentException('Illegal operator and value combination.');\n        }\n\n        return [$value, $operator];\n    }\n\n    /**\n     * Determine if the given operator and value combination is legal.\n     *\n     * Prevents using Null values with invalid operators.\n     *\n     * @param  string  $operator\n     * @param  mixed  $value\n     * @return bool\n     */\n    protected function invalidOperatorAndValue($operator, $value)\n    {\n        return is_null($value) && in_array($operator, $this->operators) &&\n             ! in_array($operator, ['=', '<=>', '<>', '!=']);","sourceCodeStart":1050,"sourceCodeEnd":1086,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Database/Query/Builder.php#L1050-L1086","documentation":"prepareValueAndError/prepareValueAndOperator validates the operator+value pair for a where clause. invalidOperatorAndValue() returns true when the value is null but the operator is not one of the null-safe ones ('=', '<>', '!=', '<=>'); combining a null value with operators like '>', '<', 'like' is ambiguous SQL and is rejected. The two-argument form (where('col', 'value')) sets useDefault and is exempt.","triggerScenarios":"->where('column', '>', null), ->where('price', '<', null), ->where('name', 'like', null) — any where() with an explicit comparison operator and a null value that the operator cannot meaningfully apply to.","commonSituations":"A variable that should hold a value but came back null from input/request data; nullable columns compared with comparison operators instead of whereNull(); API clients sending null for a filter; building dynamic where clauses without null-checking the input.","solutions":["When the value can be null, branch to whereNull()/whereNotNull() instead of using a comparison operator.","Default or coerce the incoming value before passing it to where() (e.g. fall back to 0 or '').","Use the two-argument form ->where('col', $value) when you want an equality check, and let Laravel treat null correctly."],"exampleFix":"// before\n->where('published_at', '>', $request->since)  // $request->since is null\n\n// after\n->when($request->since, fn ($q) => $q->where('published_at', '>', $request->since))","handlingStrategy":"validation","validationCode":"$operator = '>';\nif ($value === null && ! in_array($operator, ['=', '<>', '!=', '<=>'], true)) {\n    // route to whereNull/whereNotNull instead\n    $query->whereNull('column');\n} else {\n    $query->where('column', $operator, $value);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Branch on null inputs and use whereNull()/whereNotNull() rather than a comparison operator.","Use when()/unless() to apply where() only when a filter value is present.","Validate/cast request input before it reaches the query layer."],"tags":["query-builder","where","null-handling","database"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}