{"record":{"id":"396c009c9429c3e5","repo":"z-song/laravel-admin","slug":"hasmany-field-must-be-a-hasmany-or-morphmany-relat","errorCode":null,"errorMessage":"hasMany field must be a HasMany or MorphMany relation.","messagePattern":"hasMany field must be a HasMany or MorphMany relation\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"src/Form/Field/HasMany.php","lineNumber":416,"sourceCode":"    /**\n     * Build Nested form for related data.\n     *\n     * @throws \\Exception\n     *\n     * @return array\n     */\n    protected function buildRelatedForms()\n    {\n        if (is_null($this->form)) {\n            return [];\n        }\n\n        $model = $this->form->model();\n\n        $relation = call_user_func([$model, $this->relationName]);\n\n        if (!$relation instanceof Relation && !$relation instanceof MorphMany) {\n            throw new \\Exception('hasMany field must be a HasMany or MorphMany relation.');\n        }\n\n        $forms = [];\n\n        /*\n         * If redirect from `exception` or `validation error` page.\n         *\n         * Then get form data from session flash.\n         *\n         * Else get data from database.\n         */\n        if ($values = old($this->column)) {\n            foreach ($values as $key => $data) {\n                if ($data[NestedForm::REMOVE_FLAG_NAME] == 1) {\n                    continue;\n                }\n\n                $model = $relation->getRelated()->replicate()->forceFill($data);","sourceCodeStart":398,"sourceCodeEnd":434,"githubUrl":"https://github.com/z-song/laravel-admin/blob/67c441eb78ecc5437e59775d89770cd9c2cb1e05/src/Form/Field/HasMany.php#L398-L434","documentation":"Error \"hasMany field must be a HasMany or MorphMany relation.\" thrown in z-song/laravel-admin.","triggerScenarios":"Thrown at src/Form/Field/HasMany.php:416 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"67c441eb78ecc5437e59775d89770cd9c2cb1e05","analyzedAt":"2026-08-21T02:51:03.143Z","schemaVersion":2},"datasetVersion":"2026-08-21T03:17:12.404Z"}