Code Duplication    Length = 16-23 lines in 2 locations

src/Form.php 2 locations

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