From 0f58e0f1eb87f7f027298701a65cb83882fa4978 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Tue, 7 Mar 2023 23:14:11 +0100 Subject: [PATCH] fixed update missing values --- src/MediaController.php | 4 ++-- tests/Feature/UpdateTest.php | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/MediaController.php b/src/MediaController.php index e9e9562..cbad49c 100644 --- a/src/MediaController.php +++ b/src/MediaController.php @@ -64,9 +64,9 @@ class MediaController $rules = collect($media->model->getMediaCollection($media->collection_name)->runCallback('withPropertyValidation', $media->file_name)) ->mapWithKeys(fn ($rule, $key) => ["properties.{$key}" => $rule])->toArray(); - $request->validate($rules); + $validated = $request->validate($rules); - $media->update(['custom_properties' => $request->properties]); + $media->update(['custom_properties' => data_get($validated, 'properties', [])]); return MediaData::from($media); } diff --git a/tests/Feature/UpdateTest.php b/tests/Feature/UpdateTest.php index 49ace0d..d948fcb 100644 --- a/tests/Feature/UpdateTest.php +++ b/tests/Feature/UpdateTest.php @@ -15,12 +15,15 @@ test('it updates a single files properties', function () { $response = $this->patchJson("/mediaupload/{$media->id}", [ 'properties' => [ 'test' => 'new', + 'missing' => 'value', ], ]); $response->assertStatus(200); $this->assertEquals('new', $media->fresh()->getCustomProperty('test')); + $this->assertEquals(null, $media->fresh()->getCustomProperty('missing')); $response->assertJsonPath('properties.test', 'new'); + $response->assertJsonMissingPath('properties.missing'); }); test('it validates a single files properties', function () {