Code Duplication    Length = 16-23 lines in 2 locations

src/Form.php 2 locations

@@ 714-729 (lines=16) @@
711
                        $relation->sync($prepared[$name]);
712
                    }
713
                    break;
714
                case Relations\HasOne::class:
715
716
                    $related = $this->model->$name;
717
718
                    // if related is empty
719
                    if (is_null($related)) {
720
                        $related = $relation->getRelated();
721
                        $related->{$relation->getForeignKeyName()} = $this->model->{$this->model->getKeyName()};
722
                    }
723
724
                    foreach ($prepared[$name] as $column => $value) {
725
                        $related->setAttribute($column, $value);
726
                    }
727
728
                    $related->save();
729
                    break;
730
                case Relations\BelongsTo::class:
731
732
                    $parent = $this->model->$name;
@@ 730-752 (lines=23) @@
727
728
                    $related->save();
729
                    break;
730
                case Relations\BelongsTo::class:
731
732
                    $parent = $this->model->$name;
733
734
                    // if related is empty
735
                    if (is_null($parent)) {
736
                        $parent = $relation->getRelated();
737
                    }
738
739
                    foreach ($prepared[$name] as $column => $value) {
740
                        $parent->setAttribute($column, $value);
741
                    }
742
743
                    $parent->save();
744
745
                    // When in creating, associate two models
746
                    if (!$this->model->{$relation->getForeignKey()}) {
747
                        $this->model->{$relation->getForeignKey()} = $parent->getKey();
748
749
                        $this->model->save();
750
                    }
751
752
                    break;
753
                case Relations\MorphOne::class:
754
                    $related = $this->model->$name;
755
                    if (is_null($related)) {