嗯,這裏是我做過什麼:傳遞數據庫的數據以JSON對象laravel
public function api_index()
{
$agents=DB::table('users')
->select('id','username','role')
->get();
return response()->json($agents);
}
及其在瀏覽器中拋出這樣的:
[{"id":"1","username":"suzan","role":"Admin"}, {"id":"2","username":"momta","role":"admin"}]
但我真正需要的是我需要一個json對象和該json對象我需要這些數據。可能是這樣的:
{"jsonboject":[{"id":"1","username":"suzan","role":"Admin"},{"id":"2","username":"momta","role":"admin"}]}
我該怎麼做?
謝謝你的答案 –