1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-06 04:44:04 +00:00

merge default values with sync attributes and tests

This commit is contained in:
Abrar Ahmad 2022-08-30 12:29:52 +05:00
parent 80496fb0f0
commit d22224c945
2 changed files with 31 additions and 25 deletions

View file

@ -122,14 +122,18 @@ class UpdateSyncedResource extends QueueableListener
protected function getAttributesForCreation(Syncable $model): array
{
$attributes = $model->getAttributes();
if ($model->getResourceCreationAttributes()) {
// If the developer provided a key-value array, we'd use them as it
// If the developer provided a plain array, we'd use them to pick model attributes
$attributes = Arr::isAssoc($model->getResourceCreationAttributes()) ? $model->getResourceCreationAttributes() : $model->only($model->getResourceCreationAttributes());
if (! $model->getResourceCreationAttributes()) {
// Creation attributes are not specified so create the model as 1:1 copy
return $model->getAttributes();
}
return $attributes;
if (Arr::isAssoc($model->getResourceCreationAttributes())) {
// Developer provided the default values
// We will merge the default values with sync attributes
return array_merge($model->getResourceCreationAttributes(), $model->only($model->getSyncedAttributeNames()));
}
// Developer provided the attribute names, so we'd use them to pick model attributes
return $model->only($model->getResourceCreationAttributes());
}
}