in my one of models such as posts i have a column array as featured_image and when i get result query from this model that return all of this array items, for example:
"featured_image": {
"images": {
"original": "/uploads/post_images/2020/1598873165.jpg",
"300": "/uploads/post_images/2020/300_1598873165.jpg",
"900": "/uploads/post_images/2020/900_1598873165.jpg"
},
"thumbnail": "/uploads/post_images/2020/300_1598873165.jpg"
},
now how can i modify this below query to get only one item from this array such as thumbnail?
public function allData()
{
$posts = Post::with(['groups', 'categories' => function ($query) {
$query->whereLocked(false);
}])->wherePublished(true)->get();
return response()->json([
'posts' => $posts,
], 200);
}
featured_imagesis a relation or what?featured_imageis a column onPostsmodeljoin()(or similar) to extractfeatured_image->thumbnailto a column, then pass forward in your response. You could iterate$postsand do$post->thumbnail = $post->feature_image->thumbnail;, but that's potentially quite slow.