Skip to content

Commit

Permalink
Standardizing whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
weotch authored Oct 17, 2023
1 parent 8219352 commit 4399fef
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/Cloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ public function duplicate($model, $relation = null) {
$this->dispatchOnCloningEvent($clone, $relation, $model);

if ($relation) {
if (!is_a($relation, 'Illuminate\Database\Eloquent\Relations\BelongsTo')) {
$relation->save($clone);
}
if (!is_a($relation, 'Illuminate\Database\Eloquent\Relations\BelongsTo')) {
$relation->save($clone);
}
} else {
$clone->save();
}
Expand Down Expand Up @@ -98,7 +98,7 @@ protected function cloneModel($model) {
* Duplicate all attachments, given them a new name, and update the attribute
* value
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Illuminate\Database\Eloquent\Model $model
* @param \Illuminate\Database\Eloquent\Model $clone
* @return void
*/
Expand Down Expand Up @@ -127,7 +127,7 @@ protected function dispatchOnCloningEvent($clone, $relation = null, $src = null,
$this->events->dispatch('cloner::cloning: '.get_class($src), [$clone, $src]);
}

/**
/**
* @param \Illuminate\Database\Eloquent\Model $clone
* @param \Illuminate\Database\Eloquent\Model $src The orginal model
* @return void
Expand Down Expand Up @@ -192,12 +192,14 @@ protected function duplicatePivotedRelation($relation, $relation_name, $clone) {
$foreign->pivot->getCreatedAtColumn(),
$foreign->pivot->getUpdatedAtColumn()
]);
foreach (array_keys($pivot_attributes) as $attributeKey) {
$pivot_attributes[$attributeKey] = $foreign->pivot->getAttribute($attributeKey);
}
if ($foreign->pivot->incrementing) {

foreach (array_keys($pivot_attributes) as $attributeKey) {
$pivot_attributes[$attributeKey] = $foreign->pivot->getAttribute($attributeKey);
}

if ($foreign->pivot->incrementing) {
unset($pivot_attributes[$foreign->pivot->getKeyName()]);
}
}

$clone->$relation_name()->attach($foreign, $pivot_attributes);
});
Expand All @@ -215,10 +217,10 @@ protected function duplicatePivotedRelation($relation, $relation_name, $clone) {
protected function duplicateDirectRelation($relation, $relation_name, $clone) {
$relation->get()->each(function($foreign) use ($clone, $relation_name) {
$cloned_relation = $this->duplicate($foreign, $clone->$relation_name());
if (is_a($clone->$relation_name(), 'Illuminate\Database\Eloquent\Relations\BelongsTo')) {
$clone->$relation_name()->associate($cloned_relation);
$clone->save();
}
});
if (is_a($clone->$relation_name(), 'Illuminate\Database\Eloquent\Relations\BelongsTo')) {
$clone->$relation_name()->associate($cloned_relation);
$clone->save();
}
});
}
}

0 comments on commit 4399fef

Please sign in to comment.