我是新来拉威尔的。我正在使用函数创建一个json结构。这是我当前的输出:
{
"success": "1",
"data": [
{
"category_type_id": 1,
"category_type": "Study",
"category_icon": "http://192.168.1.132:8000/images/category/study.svg"
},
{
"category_type_id": 2,
"category_type": "Sports",
"category_icon": "http://192.168.1.132:8000/images/category/game.svg"
},
{
"category_type_id": 3,
"category_type": "Other",
"category_icon": "http://192.168.1.132:8000/images/category/other.svg"
}
]
}
这是我的控制器代码:
$get_all_category = CategoryType::all();
return response()->json(['success' => '1', 'data' => $get_all_category]);
我希望结果没有数组,这是从数据开始plz需要解决方案
发布于 2019-05-19 23:56:05
只需从您的json响应中删除其他属性:
$get_all_category = CategoryType::all();
return response()->json($get_all_category);
它将像这样返回您的json:
[
{
"category_type_id": 1,
"category_type": "Study",
"category_icon": "http://192.168.1.132:8000/images/category/study.svg"
},
{
"category_type_id": 2,
"category_type": "Sports",
"category_icon": "http://192.168.1.132:8000/images/category/game.svg" },
{
"category_type_id": 3
"category_type": "Other",
"category_icon": "http://192.168.1.132:8000/images/category/other.svg"
}
]
如果你想保持成功属性,你可以这样做,但它只会将你想要删除的旧数据属性更改为'0':
$get_all_category = CategoryType::all();
return response()->json(['success' =>'1', $get_all_category]);
https://stackoverflow.com/questions/56207995
复制相似问题