| @@ 744-759 (lines=16) @@ | ||
| 741 | $relation->sync($prepared[$name]); |
|
| 742 | } |
|
| 743 | break; |
|
| 744 | case Relations\HasOne::class: |
|
| 745 | ||
| 746 | $related = $this->model->$name; |
|
| 747 | ||
| 748 | // if related is empty |
|
| 749 | if (is_null($related)) { |
|
| 750 | $related = $relation->getRelated(); |
|
| 751 | $related->{$relation->getForeignKeyName()} = $this->model->{$this->model->getKeyName()}; |
|
| 752 | } |
|
| 753 | ||
| 754 | foreach ($prepared[$name] as $column => $value) { |
|
| 755 | $related->setAttribute($column, $value); |
|
| 756 | } |
|
| 757 | ||
| 758 | $related->save(); |
|
| 759 | break; |
|
| 760 | case Relations\BelongsTo::class: |
|
| 761 | ||
| 762 | $parent = $this->model->$name; |
|
| @@ 760-782 (lines=23) @@ | ||
| 757 | ||
| 758 | $related->save(); |
|
| 759 | break; |
|
| 760 | case Relations\BelongsTo::class: |
|
| 761 | ||
| 762 | $parent = $this->model->$name; |
|
| 763 | ||
| 764 | // if related is empty |
|
| 765 | if (is_null($parent)) { |
|
| 766 | $parent = $relation->getRelated(); |
|
| 767 | } |
|
| 768 | ||
| 769 | foreach ($prepared[$name] as $column => $value) { |
|
| 770 | $parent->setAttribute($column, $value); |
|
| 771 | } |
|
| 772 | ||
| 773 | $parent->save(); |
|
| 774 | ||
| 775 | // When in creating, associate two models |
|
| 776 | if (!$this->model->{$relation->getForeignKey()}) { |
|
| 777 | $this->model->{$relation->getForeignKey()} = $parent->getKey(); |
|
| 778 | ||
| 779 | $this->model->save(); |
|
| 780 | } |
|
| 781 | ||
| 782 | break; |
|
| 783 | case Relations\MorphOne::class: |
|
| 784 | $related = $this->model->$name; |
|
| 785 | if (is_null($related)) { |
|