fixed update missing values

This commit is contained in:
philipp lang 2023-03-07 23:14:11 +01:00
parent 87265191f2
commit 0f58e0f1eb
2 changed files with 5 additions and 2 deletions

View File

@ -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);
}

View File

@ -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 () {