{"record":{"id":"0792aaf52d8984f2","repo":"laravel/framework","slug":"items-cannot-be-represented-by-a-scalar-value","errorCode":null,"errorMessage":"Items cannot be represented by a scalar value.","messagePattern":"Items cannot be represented by a scalar value\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/Arr.php","lineNumber":475,"sourceCode":"     * @template TValue = mixed\n     *\n     * @param  array<TKey, TValue>|Enumerable<TKey, TValue>|Arrayable<TKey, TValue>|WeakMap<object, TValue>|Traversable<TKey, TValue>|Jsonable|JsonSerializable|object  $items\n     * @return ($items is WeakMap ? list<TValue> : array<TKey, TValue>)\n     *\n     * @throws \\InvalidArgumentException\n     */\n    public static function from($items)\n    {\n        return match (true) {\n            is_array($items) => $items,\n            $items instanceof Enumerable => $items->all(),\n            $items instanceof Arrayable => $items->toArray(),\n            $items instanceof WeakMap => iterator_to_array($items, false),\n            $items instanceof Traversable => iterator_to_array($items),\n            $items instanceof Jsonable => json_decode($items->toJson(), true),\n            $items instanceof JsonSerializable => (array) $items->jsonSerialize(),\n            is_object($items) => (array) $items,\n            default => throw new InvalidArgumentException('Items cannot be represented by a scalar value.'),\n        };\n    }\n\n    /**\n     * Get an item from an array using \"dot\" notation.\n     *\n     * @param  \\ArrayAccess|array  $array\n     * @param  string|int|null  $key\n     * @param  mixed  $default\n     * @return mixed\n     */\n    public static function get($array, $key, $default = null)\n    {\n        if (! static::accessible($array)) {\n            return value($default);\n        }\n\n        if (is_null($key)) {","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/Arr.php#L457-L493","documentation":"Thrown by Arr::from() when $items is a scalar (int, float, bool, or plain string) that matches none of the match arms (array, Enumerable, Arrayable, WeakMap, Traversable, Jsonable, JsonSerializable, object). Scalars hit the default arm and throw.","triggerScenarios":"Calling Arr::from(42), Arr::from('hello'), Arr::from(true), or Arr::from(3.14). Also when a variable expected to be iterable holds a scalar.","commonSituations":"Passing user input that is sometimes a scalar string instead of an array; decoding JSON without forcing arrays; loose typing across API boundaries.","solutions":["Wrap scalars before passing: Arr::from([$value]) or Arr::from((array) $value).","Validate with is_iterable()/is_array() upstream and normalize.","Force array decoding: json_decode($json, true)."],"exampleFix":"// before\n$arr = Arr::from($maybeScalar); // throws on 'foo'\n// after\n$arr = Arr::from(is_array($maybeScalar) ? $maybeScalar : [$maybeScalar]);","handlingStrategy":"type-guard","validationCode":"if (is_array($items) || $items instanceof \\Traversable || $items instanceof \\Illuminate\\Contracts\\Support\\Arrayable) {\n    $arr = Arr::from($items);\n} elseif (is_scalar($items)) {\n    $arr = [$items];\n} else {\n    $arr = [];\n}","typeGuard":"function isFromable(mixed $items): bool {\n    return is_array($items)\n        || $items instanceof \\Traversable\n        || $items instanceof \\Illuminate\\Contracts\\Support\\Arrayable\n        || $items instanceof \\Illuminate\\Contracts\\Support\\Jsonable\n        || $items instanceof \\JsonSerializable\n        || is_object($items);\n}","tryCatchPattern":"try {\n    $arr = Arr::from($maybeScalar);\n} catch (\\InvalidArgumentException $e) {\n    $arr = is_scalar($maybeScalar) ? [$maybeScalar] : [];\n}","preventionTips":["Wrap unknown scalars in an array before Arr::from().","Force JSON arrays with json_decode($json, true).","Validate is_iterable()/is_array() at API boundaries."],"tags":["collections","array","type-mismatch","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}