{"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/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/Arr.php#L457-L493","documentation":"Thrown by Arr::from() when the supplied $items is a bare scalar (string, int, float, bool) — the match statement in from() has no arm for scalars and falls through to the default that throws. from() expects an iterable/array-like (array, Enumerable, Arrayable, WeakMap, Traversable, Jsonable, JsonSerializable, or object).","triggerScenarios":"Calling Arr::from('hello') or Arr::from(42); passing a scalar where an iterable is required.","commonSituations":"Loosely-typed code that sometimes receives a single scalar instead of a list; JSON decode returning a scalar (e.g. json_decode('\"hi\"')); a helper that wraps its argument but accidentally calls from() instead of wrap().","solutions":["Use Arr::wrap($items) instead if you want a scalar promoted to a single-element array.","Validate the input is iterable before calling Arr::from().","Fix the producer to always pass an array/Collection.","Branch on type: is_array($x) ? Arr::from($x) : Arr::from([$x])."],"exampleFix":"// before\n$items = Arr::from($maybeScalar);\n\n// after\n$items = Arr::wrap($maybeScalar);\n// or\n$items = Arr::from(is_iterable($maybeScalar) ? $maybeScalar : [$maybeScalar]);","handlingStrategy":"type-guard","validationCode":"if (! is_iterable($items) && ! ($items instanceof \\Illuminate\\Contracts\\Support\\Arrayable) && ! is_object($items)) {\n    $items = [$items]; // wrap scalars instead of calling Arr::from()\n}","typeGuard":"function isFromable(mixed $items): bool {\n    return is_iterable($items)\n        || $items instanceof \\Illuminate\\Contracts\\Support\\Arrayable\n        || $items instanceof \\JsonSerializable\n        || $items instanceof \\Illuminate\\Contracts\\Support\\Jsonable\n        || is_object($items);\n}","tryCatchPattern":"try {\n    $arr = Arr::from($input);\n} catch (\\InvalidArgumentException $e) {\n    $arr = [$input];\n}","preventionTips":["Prefer Arr::wrap() when scalars should be promoted to a single-element array.","Validate the producer always emits an array or Collection.","Guard dynamic inputs with is_iterable() before Arr::from()."],"tags":["collections","arrays","type-mismatch","laravel"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}