刪除[數據]我試過用雄辯和分形Laravel從收集
$lists = Category::all();
$result = Fractal::collection($lists, new CategoryTransformer())->getArray();
查詢並返回它
return response()->json((['code' => "200", 'results' => $result]));
JSON結果是這樣的:
{"code":"200","results":{"data":[{"id":"1","name":"Cafe","logo":null,"cover":""},{"id":"2","name":"SPA","logo":null,"cover":""},{"id":"3","name":"Hotel","logo":null,"cover":""}]}}
如何刪除結果後的「數據」?所以我可以只獲得沒有「數據」的數組。
我已經試過:
$result = Fractal::collection($lists, new CategoryTransformer(), 'results')->getArray();
return (['code' => "200", $result]);
還給我:
{"code":"200","0":{"results":[{"id":"1","name":"Cafe","logo":"","cover":""},{"id":"2","name":"SPA","logo":"","cover":""},{"id":"3","name":"Hotel","logo":"","cover":""}]}}
結果之前,有一條通往 '0'。我如何刪除它?
感謝
''result'沒有' - > getArray()'的結果是什麼? – aldrin27
嗨,感謝您的回答。 結果爲空{}。 – ssuhat
你可以使用foreach操作你的數組 – aldrin27