我有一张桌子
trend
其中我有一列
hashtags
hastags
列作为数组。
用雄辩的语言表达如下。
$singleData = Trend::find($id);
{
"status": "200",
"isError": false,
"data": {
"message": "Trend found.",
"singleData": {
"id": 1,
"title": "first trend",
"start_date": "2018-11-16",
"end_date": "2018-11-16",
"slug": "first-trend",
"hashtags": "first,trend,second",
"created_by": 1,
"status": false,
"created_at": "2018-11-16 00:00:00",
"updated_at": "2018-11-19 08:51:20"
}
}
}
我希望结果如下
{
"status": "200",
"isError": false,
"data": {
"message": "Trend found.",
"singleData": {
"id": 1,
"title": "first trend",
"start_date": "2018-11-16",
"end_date": "2018-11-16",
"slug": "first-trend",
"hashtags": [
"first",
"trend",
"second"
],
"created_by": 1,
"status": false,
"created_at": "2018-11-16 00:00:00",
"updated_at": "2018-11-19 08:51:20"
}
}
}
我在我的工作中使用了下面的代码,得到了这个结果
TrendController
.
$singleData->hashtags = explode(',', $singleData->hashtags);
但如果可能的话,我希望有更好的方法用雄辩的口才来获取信息。