어떻게이 Laravel 컬렉션 배열을 아래와 같이 json 형식으로 변환 할 수 있습니까?Laravel 컬렉션 배열을 json으로 변환하는 방법
//All records from users table.
$users = DB::table('users')->get();
// Required json format.
return '{
"data": [
{
"DT_RowId": "row_1",
"id": "Tiger",
"clear": "Nixon",
"fsssf": "System Architect",
"tex": "[email protected]",
"created_at": "Edinburgh",
"updated_at": "Edinburgh"
},
{
"DT_RowId": "row_2",
"id": "Tiger",
"clear": "Nixon",
"fsssf": "System Architect",
"tex": "[email protected]",
"created_at": "Edinburgh",
"updated_at": "Edinburgh"
}
],
"options": [],
"files": []
}';
미안하지만이 jso로 변환 할 수 없습니다.
$ users는 컬렉션이며 "-> toJson()"메소드가 있습니다. – inet123