From 13b1e9b18cf6c0ca759c1cd6fe958dce38c9940c Mon Sep 17 00:00:00 2001 From: Chris Pymm Date: Wed, 22 Sep 2021 14:06:09 +0100 Subject: [PATCH] update to fix bug with creting new models --- src/Repositories/Behaviours/HandleMetadata.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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();