Skip to content

Commit 6ae8f46

Browse files
committed
feat: performFill wrapper method
1 parent 4fcf4de commit 6ae8f46

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

src/Concerns/HandlesRelationStandardOperations.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,7 @@ protected function performStore(
340340
array $attributes,
341341
array $pivot
342342
): void {
343-
$entity->fill(
344-
Arr::except($attributes, array_keys($entity->getDirty()))
345-
);
343+
$this->performFill($request, $parentEntity, $entity, $attributes, $pivot);
346344

347345
if (!$parentEntity->{$this->getRelation()}() instanceof BelongsTo) {
348346
$parentEntity->{$this->getRelation()}()->save($entity, $this->preparePivotFields($pivot));
@@ -684,9 +682,7 @@ protected function performUpdate(
684682
array $attributes,
685683
array $pivot
686684
): void {
687-
$entity->fill(
688-
Arr::except($attributes, array_keys($entity->getDirty()))
689-
);
685+
$this->performFill($request, $parentEntity, $entity, $attributes, $pivot);
690686
$entity->save();
691687

692688
$relation = $parentEntity->{$this->getRelation()}();
@@ -1016,4 +1012,25 @@ protected function afterRestore(Request $request, Model $parentEntity, Model $en
10161012
{
10171013
return null;
10181014
}
1015+
1016+
/**
1017+
* Fills attributes on the given relation entity.
1018+
*
1019+
* @param Request $request
1020+
* @param Model $parentEntity
1021+
* @param Model $entity
1022+
* @param array $attributes
1023+
* @param array $pivot
1024+
*/
1025+
protected function performFill(
1026+
Request $request,
1027+
Model $parentEntity,
1028+
Model $entity,
1029+
array $attributes,
1030+
array $pivot
1031+
): void {
1032+
$entity->fill(
1033+
Arr::except($attributes, array_keys($entity->getDirty()))
1034+
);
1035+
}
10191036
}

src/Concerns/HandlesStandardOperations.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,7 @@ protected function beforeSave(Request $request, Model $entity)
207207
*/
208208
protected function performStore(Request $request, Model $entity, array $attributes): void
209209
{
210-
$entity->fill(
211-
Arr::except($attributes, array_keys($entity->getDirty()))
212-
);
210+
$this->performFill($request, $entity, $attributes);
213211
$entity->save();
214212
}
215213

@@ -426,9 +424,7 @@ protected function beforeUpdate(Request $request, Model $entity)
426424
*/
427425
protected function performUpdate(Request $request, Model $entity, array $attributes): void
428426
{
429-
$entity->fill(
430-
Arr::except($attributes, array_keys($entity->getDirty()))
431-
);
427+
$this->performFill($request, $entity, $attributes);
432428
$entity->save();
433429
}
434430

@@ -664,4 +660,18 @@ protected function afterRestore(Request $request, Model $entity)
664660
{
665661
return null;
666662
}
663+
664+
/**
665+
* Fills attributes on the given entity.
666+
*
667+
* @param Request $request
668+
* @param Model $entity
669+
* @param array $attributes
670+
*/
671+
protected function performFill(Request $request, Model $entity, array $attributes): void
672+
{
673+
$entity->fill(
674+
Arr::except($attributes, array_keys($entity->getDirty()))
675+
);
676+
}
667677
}

0 commit comments

Comments
 (0)