Id like to overwrite a relationship attribute like the following:
$article['tags'] = $article->tags->pluck('title');
return compact('article');
It fails because it returns the tags attribute as an array of objects instead of an array of title strings. The API consumer needs the data in that form. This also reduces the size of the payload.
My current work around is to add another attribute and unset the original one.
$article['tagged'] = $article->tags->pluck('title');
unset($article['tags']);
return compact('article');
But I wish it was simpler and straightforward.
$article['tags'] = $article->tags()->pluck('title');titlefrom tags relation instead ?