diff --git a/src/Contracts/BaseSyncable.php b/src/Contracts/BaseSyncable.php new file mode 100644 index 00000000..e9ab18ff --- /dev/null +++ b/src/Contracts/BaseSyncable.php @@ -0,0 +1,18 @@ +model->getCentralModelName()::create($event->model->getAttributes()); + $centralModel = $event->model->getCentralModelName()::create($event->model->only($event->model->getCentralModelFillable())); event(new SyncedResourceChangedInForeignDatabase($event->model, null)); } }); @@ -113,7 +113,7 @@ class UpdateSyncedResource extends QueueableListener $localModel->update($syncedAttributes); } else { // When creating, we use all columns, not just the synced ones. - $localModel = $localModelClass::create($eventModel->getAttributes()); + $localModel = $localModelClass::create($eventModel->only($eventModel->getTenantModelFillable())); } event(new SyncedResourceChangedInForeignDatabase($localModel, $tenant)); diff --git a/tests/ResourceSyncingTest.php b/tests/ResourceSyncingTest.php index 570448d1..b30c1c4b 100644 --- a/tests/ResourceSyncingTest.php +++ b/tests/ResourceSyncingTest.php @@ -603,6 +603,11 @@ class CentralUser extends Model implements SyncMaster return ResourceUser::class; } + public function getTenantModelFillable(): array + { + return (new ResourceUser)->getFillable(); + } + public function getGlobalIdentifierKey() { return $this->getAttribute($this->getGlobalIdentifierKeyName()); @@ -651,6 +656,11 @@ class ResourceUser extends Model implements Syncable return CentralUser::class; } + public function getCentralModelFillable(): array + { + return (new CentralUser)->getFillable(); + } + public function getSyncedAttributeNames(): array { return [