protected function buildRelatedForms()
    {
        if (is_null($this->form)) {
            return [];
        }

        $model = $this->form->model();

        $relation = call_user_func([$model, $this->relationName]);

        if (!$relation instanceof Relation && !$relation instanceof MorphMany) {
            throw new \Exception('hasMany field must be a HasMany or MorphMany relation.');
        }

        $forms = [];

        /*
         * If redirect from `exception` or `validation error` page.
         *
         * Then get form data from session flash.
         *
         * Else get data from database.
         */
        if ($values = old($this->column)) {
            foreach ($values as $key => $data) {
                if ($data[NestedForm::REMOVE_FLAG_NAME] == 1) {
                    continue;
                }

                $model = $relation->getRelated()->replicate()->forceFill($data);

                $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $model)
                    ->fill($data);
            }
        } else {
            foreach ($this->value as $data) {
                $key = Arr::get($data, $relation->getRelated()->getKeyName());

                $model = $relation->getRelated()->replicate()->forceFill($data);

                $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $model)
                    ->fill($data);
            }
        }

        return $forms;
    }
protected function buildRelatedForms()
    {
        if (is_null($this->form)) {
            return [];
        }

        $model = $this->form->model();

        $relation = call_user_func([$model, $this->relationName]);

        if (!$relation instanceof Relation && !$relation instanceof MorphMany) {
            throw new \Exception('hasMany field must be a HasMany or MorphMany relation.');
        }

        $forms = [];

        /*
         * If redirect from `exception` or `validation error` page.
         *
         * Then get form data from session flash.
         *
         * Else get data from database.
         */
        if ($values = old($this->column)) {
            foreach ($values as $key => $data) {
                if ($data[NestedForm::REMOVE_FLAG_NAME] == 1) {
                    continue;
                }

                $model = $relation->getRelated()->replicate()->forceFill($data);

                $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $model)
                    ->fill($data);
            }
        } else {
            foreach ($this->value as $data) {
                $key = Arr::get($data, $relation->getRelated()->getKeyName());

                $model = $relation->getRelated()->replicate()->forceFill($data);

                $forms[$key] = $this->buildNestedForm($this->column, $this->builder, $model)
                    ->fill($data);
            }
        }

        return $forms;
    }
protected function buildRelatedForms ( ) { if ( is_null ( $ this -> form ) ) { return [ ] ; } $ model = $ this -> form -> model ( ) ; $ relation = call_user_func ( [ $ model , $ this -> relationName ] ) ; if ( ! $ relation instanceof Relation && ! $ relation instanceof MorphMany ) { throw new \ Exception ( 'hasMany field must be a HasMany or MorphMany relation.' ) ; } $ forms = [ ] ; /*
         * If redirect from `exception` or `validation error` page.
         *
         * Then get form data from session flash.
         *
         * Else get data from database.
         */ if ( $ values = old ( $ this -> column ) ) { foreach ( $ values as $ key => $ data ) { if ( $ data [ NestedForm :: REMOVE_FLAG_NAME ] == 1 ) { continue ; } $ model = $ relation -> getRelated ( ) -> replicate ( ) -> forceFill ( $ data ) ; $ forms [ $ key ] = $ this -> buildNestedForm ( $ this -> column , $ this -> builder , $ model ) -> fill ( $ data ) ; } } else { foreach ( $ this -> value as $ data ) { $ key = Arr :: get ( $ data , $ relation -> getRelated ( ) -> getKeyName ( ) ) ; $ model = $ relation -> getRelated ( ) -> replicate ( ) -> forceFill ( $ data ) ; $ forms [ $ key ] = $ this -> buildNestedForm ( $ this -> column , $ this -> builder , $ model ) -> fill ( $ data ) ; } } return $ forms ; }
Build Nested form for related data.

@throws \Exception

@return array
Build Nested form for related data .