0
所以我执行查询和获取数据传回这样的:Laravel从查询返回简化JSON
[
{ "part_number": "MAC0009", "description": "Accessory Stand Foot" },
{ "part_number": "MAC0010", "description": "Accessory Stand Collar Tapped M5" },
{ "part_number": "MAC0011", "description": "Accessory Stand Top Collar" },
{ "part_number": "MAC0012", "description": "25mm Round Knob With 2 Rail Holes" }
]
不过,对于AJAX脚本,我想要实现我需要在这个格式的数据:
[
{ "MAC0009" : "Accessory Stand Foot" },
{ "MAC00010" : "Accessory Stand Collar Tapped M5" },
{ "MAC00012" : "Accessory Stand Top Collar" }
]
所以基本上我需要原始数据返回没有表名称。
我到目前为止所有的查询。
$result = DB::table('macs')->select('part_number', 'description')->get();
这显然是不错,但我不知道如何将数据处理成格式:/任何帮助表示赞赏。
美丽的感谢。 – ZUK88