fixed update missing values
This commit is contained in:
parent
87265191f2
commit
0f58e0f1eb
|
@ -64,9 +64,9 @@ class MediaController
|
||||||
$rules = collect($media->model->getMediaCollection($media->collection_name)->runCallback('withPropertyValidation', $media->file_name))
|
$rules = collect($media->model->getMediaCollection($media->collection_name)->runCallback('withPropertyValidation', $media->file_name))
|
||||||
->mapWithKeys(fn ($rule, $key) => ["properties.{$key}" => $rule])->toArray();
|
->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);
|
return MediaData::from($media);
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,15 @@ test('it updates a single files properties', function () {
|
||||||
$response = $this->patchJson("/mediaupload/{$media->id}", [
|
$response = $this->patchJson("/mediaupload/{$media->id}", [
|
||||||
'properties' => [
|
'properties' => [
|
||||||
'test' => 'new',
|
'test' => 'new',
|
||||||
|
'missing' => 'value',
|
||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$this->assertEquals('new', $media->fresh()->getCustomProperty('test'));
|
$this->assertEquals('new', $media->fresh()->getCustomProperty('test'));
|
||||||
|
$this->assertEquals(null, $media->fresh()->getCustomProperty('missing'));
|
||||||
$response->assertJsonPath('properties.test', 'new');
|
$response->assertJsonPath('properties.test', 'new');
|
||||||
|
$response->assertJsonMissingPath('properties.missing');
|
||||||
});
|
});
|
||||||
|
|
||||||
test('it validates a single files properties', function () {
|
test('it validates a single files properties', function () {
|
||||||
|
|
Loading…
Reference in New Issue