Skip to content

Commit

Permalink
Merge pull request #2995 from hallelujahbaby/master
Browse files Browse the repository at this point in the history
Improve the logic of switch() closure in updateRelation function
  • Loading branch information
z-song committed Feb 8, 2019
2 parents 0848e3d + 2118da3 commit 58d3940
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -737,14 +737,14 @@ protected function updateRelation($relationsData)
continue;
}

switch (get_class($relation)) {
case Relations\BelongsToMany::class:
case Relations\MorphToMany::class:
switch (true) {
case $relation instanceof Relations\BelongsToMany:
case $relation instanceof Relations\MorphToMany:
if (isset($prepared[$name])) {
$relation->sync($prepared[$name]);
}
break;
case Relations\HasOne::class:
case $relation instanceof Relations\HasOne:

$related = $this->model->$name;

Expand All @@ -762,7 +762,7 @@ protected function updateRelation($relationsData)

$related->save();
break;
case Relations\BelongsTo::class:
case $relation instanceof Relations\BelongsTo:

$parent = $this->model->$name;

Expand All @@ -785,7 +785,7 @@ protected function updateRelation($relationsData)
}

break;
case Relations\MorphOne::class:
case $relation instanceof Relations\MorphOne:
$related = $this->model->$name;
if (is_null($related)) {
$related = $relation->make();
Expand All @@ -795,8 +795,8 @@ protected function updateRelation($relationsData)
}
$related->save();
break;
case Relations\HasMany::class:
case Relations\MorphMany::class:
case $relation instanceof Relations\HasMany:
case $relation instanceof Relations\MorphMany:

foreach ($prepared[$name] as $related) {
/** @var Relations\Relation $relation */
Expand Down

0 comments on commit 58d3940

Please sign in to comment.