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