abort if single media not found
This commit is contained in:
parent
278bf58551
commit
f5e9aff0be
|
@ -78,6 +78,8 @@ class MediaController
|
|||
$model = $model::find($parentId);
|
||||
$isSingle = 1 === $model->getMediaCollection($collection)->collectionSizeLimit;
|
||||
|
||||
abort_if($isSingle && !$model->getFirstMedia($collection), 404);
|
||||
|
||||
return $isSingle
|
||||
? MediaData::from($model->getFirstMedia($collection))
|
||||
: MediaData::collection($model->getMedia($collection));
|
||||
|
|
|
@ -27,3 +27,12 @@ test('it gets media for single', function () {
|
|||
$response->assertJsonPath('id', $media->id);
|
||||
$response->assertJsonPath('properties.test', 'old');
|
||||
});
|
||||
|
||||
test('it returns 404 when media not found', function () {
|
||||
$this->auth()->registerModel();
|
||||
$post = $this->newPost();
|
||||
|
||||
$response = $this->getJson("/mediaupload/post/{$post->id}/defaultSingleFile");
|
||||
|
||||
$response->assertStatus(404);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue