{"id":"58155f4e398f4f6b","repo":"laravel/framework","slug":"number-of-groups-must-be-at-least-1-58155f","errorCode":null,"errorMessage":"Number of groups must be at least 1.","messagePattern":"Number of groups must be at least 1\\.","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Illuminate/Collections/LazyCollection.php","lineNumber":1316,"sourceCode":"        if ($offset < 0 || $length < 0) {\n            return $this->passthru(__FUNCTION__, func_get_args());\n        }\n\n        $instance = $this->skip($offset);\n\n        return is_null($length) ? $instance : $instance->take($length);\n    }\n\n    /**\n     * {@inheritDoc}\n     *\n     * @throws \\InvalidArgumentException\n     */\n    #[\\Override]\n    public function split($numberOfGroups)\n    {\n        if ($numberOfGroups < 1) {\n            throw new InvalidArgumentException('Number of groups must be at least 1.');\n        }\n\n        return $this->passthru(__FUNCTION__, func_get_args());\n    }\n\n    /**\n     * Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.\n     *\n     * @param  (callable(TValue, TKey): bool)|string|null  $key\n     * @param  mixed  $operator\n     * @param  mixed  $value\n     * @return TValue\n     *\n     * @throws \\Illuminate\\Support\\ItemNotFoundException\n     * @throws \\Illuminate\\Support\\MultipleItemsFoundException\n     */\n    public function sole($key = null, $operator = null, $value = null)\n    {","sourceCodeStart":1298,"sourceCodeEnd":1334,"githubUrl":"https://github.com/laravel/framework/blob/bd6b5437e6ad87bb49f9b426724f07a9f64e9683/src/Illuminate/Collections/LazyCollection.php#L1298-L1334","documentation":"Thrown by LazyCollection::split($numberOfGroups) when the count is less than 1. This is the lazy override that delegates via passthru() to the eager Collection::split, but it validates the argument first since the underlying source may not be materialized. Same precondition as the eager version.","triggerScenarios":"Calling $lazy->split(0) or $lazy->split(-2). Often with a dynamically computed group count from a query result size that can be 0.","commonSituations":"Splitting a lazy collection (e.g. from a cursor/generator) into N batches where N is derived from config or a count that resolves to 0.","solutions":["Pass an integer >= 1 to split(); clamp with max(1, $n).","Default the group-count source to a positive value.","Guard the call site when the count may be 0 or negative."],"exampleFix":"// before\n$groups = $lazy->split($partitionCount);\n\n// after\n$groups = $lazy->split(max(1, (int) $partitionCount));","handlingStrategy":"validation","validationCode":"$groups = max(1, (int) $numberOfGroups);\n$parts = $lazy->split($groups);","typeGuard":"function isValidGroupCount($n): bool { return is_int($n) && $n >= 1; }","tryCatchPattern":"try {\n    $parts = $lazy->split($n);\n} catch (\\InvalidArgumentException $e) {\n    $parts = $lazy->chunk(1);\n}","preventionTips":["Validate lazy-collection group counts the same way as eager ones.","Default partition-count config to a positive value."],"tags":["laravel","collections","lazy","validation","invalid-argument"],"analyzedSha":"bd6b5437e6ad87bb49f9b426724f07a9f64e9683","analyzedAt":"2026-08-06T00:28:32.783Z","schemaVersion":2}