【发布时间】:2023-01-03 00:43:31
【问题描述】:
我有一个像这样的 MySQL 表:
+------+-----------------+---------+------------+
| id | name | refferal| reference |
+------+-----------------+---------+------------+
| 1 | Alex Muller | 1 | null |
| 2 | John Doe | 2 | 1 |
| 3 | Tom Foe | 3 | 1 |
| 4 | Harry Pott | 4 | 3 |
| 5 | Kate Garry | 5 | 3 |
| 6 | Mike Blue | 6 | 4 |
+------+-----------------+---------+------------+
(比这更多的数据......)
我需要使用 Laravel 将该数据转换为 JSON 文件。像这样:
[{"id":1,"name":"Alex Muller","parent":0},
{"id":2,"name":"John Doe","parent":1},
{"id":3,"name":"Tom Foe","parent":1},
{"id":4,"name":"Harry Pott","parent":3},
{"id":5,"name":"Kate Garry","parent":3},
{"id":6,"name":"Mike Blue","parent":4}]
在此之后,我将得到这样的树视图:
我只是用自己的写法制作了这个 json 文件。我不知道该怎么办。我在等你的答案。谢谢你。
【问题讨论】: