diff --git a/src/Repositories/Behaviours/HandleMetadata.php b/src/Repositories/Behaviours/HandleMetadata.php index 85e5cc7..fad3c90 100644 --- a/src/Repositories/Behaviours/HandleMetadata.php +++ b/src/Repositories/Behaviours/HandleMetadata.php @@ -30,9 +30,10 @@ public function afterSaveHandleMetadata(Model $object, array $fields) $repository = App::make('CwsDigital\TwillMetadata\Repositories\MetadataRepository'); - $repository->update($object->id, $fields); + $metadata = $object->metadata ?? $object->metadata()->create(); + + $repository->update($metadata->id, $fields); - //$object->metadata()->update($fields); } /** @@ -43,8 +44,6 @@ public function afterSaveHandleMetadata(Model $object, array $fields) * @return array */ public function getFormFieldsHandleMetadata(Model $object, array $fields){ - $repository = App::make('CwsDigital\TwillMetadata\Repositories\MetadataRepository'); - //If the metadata object doesn't exist create it. Every 'meta_describable' will need one entry. $metadata = $object->metadata ?? $object->metadata()->create();