diff --git a/src/Ushahidi/Modules/V5/Actions/Post/HandlePostOnlyParameters.php b/src/Ushahidi/Modules/V5/Actions/Post/HandlePostOnlyParameters.php index 30a981e40..447cd51c6 100644 --- a/src/Ushahidi/Modules/V5/Actions/Post/HandlePostOnlyParameters.php +++ b/src/Ushahidi/Modules/V5/Actions/Post/HandlePostOnlyParameters.php @@ -83,12 +83,17 @@ public function addHydrateRelationships(Post $post, array $hydrates) $relations['enabled_languages'] = true; break; case 'post_media': - $post->post_media = $post->valuesPostMedia; - $post->post_media = $post->post_media->map(function ($media) { - $media = $media->toArray(); - unset($media['post']); // Remove the 'post' property - return $media; - }); + $post->post_media = $post->valuesPostMedia->first(); + if ($post->post_media) { + $media = $post->post_media->toArray(); + unset($media['post']); + // convert it to field structure + $media_field = $media['attribute']; + unset($media['attribute']); + unset($media['translations']); + $media_field['value'] = $media; + $post->post_media = $media_field; + } break; } } diff --git a/src/Ushahidi/Modules/V5/Models/Post/Post.php b/src/Ushahidi/Modules/V5/Models/Post/Post.php index c92060cab..75f217aec 100644 --- a/src/Ushahidi/Modules/V5/Models/Post/Post.php +++ b/src/Ushahidi/Modules/V5/Models/Post/Post.php @@ -763,7 +763,10 @@ public function valuesPostsMedia() public function valuesPostMedia() { return $this->hasMany('Ushahidi\Modules\V5\Models\PostValues\PostMedia', 'post_id', 'id') - ->select('post_media.*'); + ->select('post_media.*')->with('attribute')->whereHas('attribute', function ($query) { + $query->where('input', 'image') + ->orWhere('input', 'upload'); // for old uploaded images + }); } public function valuesPostsSet() {