diff --git a/src/MediaController.php b/src/MediaController.php index ab5a685..b72bc10 100644 --- a/src/MediaController.php +++ b/src/MediaController.php @@ -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)); diff --git a/tests/Feature/IndexTest.php b/tests/Feature/IndexTest.php index 857b161..9f6d456 100644 --- a/tests/Feature/IndexTest.php +++ b/tests/Feature/IndexTest.php @@ -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); +});