{"record":{"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":1318,"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":1300,"sourceCodeEnd":1336,"githubUrl":"https://github.com/laravel/framework/blob/e0f6eb3518ac29fbbca8529e97d0df7fc9f24481/src/Illuminate/Collections/LazyCollection.php#L1300-L1336","documentation":"Thrown by LazyCollection::split($numberOfGroups) when the argument is < 1. split divides a lazy collection into a number of groups via passthru to the underlying eager Collection::split, and rejects an invalid group count up front with an InvalidArgumentException. This is the lazy analogue of the Collection method.","triggerScenarios":"->split(0), ->split(-3); group count derived from user input or a divisor that yields <= 0.","commonSituations":"Splitting results into N columns for display with N computed from a request; configurable bucket count defaulting to 0; dynamic value that becomes 0 on edge cases.","solutions":["Ensure $numberOfGroups >= 1: ->split(max(1, $value)).","Validate the input at the controller/request layer.","Use a sensible default when the source value is absent."],"exampleFix":"// before\n$parts = $lazy->split($request->input('buckets'));\n// after\n$buckets = max(1, (int) $request->input('buckets', 1));\n$parts = $lazy->split($buckets);","handlingStrategy":"validation","validationCode":"if ($numberOfGroups < 1) {\n    throw new \\InvalidArgumentException('numberOfGroups must be >= 1');\n}\nreturn $lazy->split($numberOfGroups);","typeGuard":"$numberOfGroups = (is_int($numberOfGroups) && $numberOfGroups >= 1) ? $numberOfGroups : 1;","tryCatchPattern":"try {\n    return $lazy->split($value);\n} catch (\\InvalidArgumentException $e) {\n    return $lazy->split(1);\n}","preventionTips":["Clamp bucket counts with max(1, $value).","Validate split inputs as integer|min:1.","Default to 1 when the source value is missing."],"tags":["lazy-collection","validation","argument-error","laravel"],"backgroundTag":null,"analyzedSha":"e0f6eb3518ac29fbbca8529e97d0df7fc9f24481","analyzedAt":"2026-08-11T20:52:37.562Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}