From c9147b5849f20531aa141a5009ff0a6711c38ed7 Mon Sep 17 00:00:00 2001 From: Ovidiu Popescu Date: Thu, 9 Feb 2023 14:10:49 +0200 Subject: [PATCH] create config key --- assets/config.php | 5 +++++ src/Listeners/UpdateSyncedResource.php | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/assets/config.php b/assets/config.php index b12cd6c4..7e51d9f5 100644 --- a/assets/config.php +++ b/assets/config.php @@ -196,4 +196,9 @@ return [ '--class' => 'DatabaseSeeder', // root seeder class // '--force' => true, ], + + /** + * Allow the resource be created in the central DB just with the synced attributes. + */ + 'created_only_with_synced_attributes' => false, ]; diff --git a/src/Listeners/UpdateSyncedResource.php b/src/Listeners/UpdateSyncedResource.php index 604b17cf..b17e49a6 100644 --- a/src/Listeners/UpdateSyncedResource.php +++ b/src/Listeners/UpdateSyncedResource.php @@ -60,7 +60,10 @@ class UpdateSyncedResource extends QueueableListener } else { // If the resource doesn't exist at all in the central DB,we create // the record with all attributes, not just the synced ones. - $centralModel = $event->model->getCentralModelName()::create($syncedAttributes); + $centralModel = $event->model->getCentralModelName()::create( + config('tenancy.created_only_with_synced_attributes') ? $syncedAttributes + : $event->model->getAttributes() + ); event(new SyncedResourceChangedInForeignDatabase($event->model, null)); } });