I have an issue with presenting data from an Eloquent model as JSON.
Let's say I have a Post model extending Eloquent. If in my route I simply return Post::find(1) I will have the following JSON :
{
id: 1,
title: "My cool blog post",
text: "This is very interesting",
type_id: 2
}
If I have an array of post types somewhere
$types = ["Type1", "Type2", "Type3", "Type4"];
How would I go adding to my json the string containing the type, transforming the string in the process (adding some exclamation marks for example) ? Expected (example):
{
id: 1,
title: "My cool blog post",
text: "This is very interesting",
type_id: 2,
type_name: "!Type3!"
}