0
我將展示來自Eloquent模型的數據視爲JSON時遇到問題。Laravel在返回JSON時呈現數據
比方說,我有一個Post模型擴展雄辯。如果我的路線,我只是回郵::發現(1)我將有以下JSON:
{
id: 1,
title: "My cool blog post",
text: "This is very interesting",
type_id: 2
}
如果我有職位類型的數組某處
$types = ["Type1", "Type2", "Type3", "Type4"];
我怎麼會去增加我的JSON包含類型的字符串,轉換過程中的字符串(例如添加一些感嘆號)?預期(例如):
{
id: 1,
title: "My cool blog post",
text: "This is very interesting",
type_id: 2,
type_name: "!Type3!"
}