php - 复杂的 laravel 雄辩查询
问题描述
我们有下表结构。
clients
-id
-name
projects
-id
-title
-client_id
project_type
-id
-name
-parent_id
project_type_cost
-id
-amount
-project_id
-project_type_id
project_type表结构,它们与自身有很多关系。
我已经为每个表创建了模型并且能够理解关系。我能够理解这种关系,但无法生成预期的输出,如下所示。客户金额是项目总成本,项目成本是所有项目类型的成本。我们还需要在 client_id、project_id、project_type_id 上添加过滤器。
{
"id":1,
"name":"XYZ",
"amount":1234,
"type":"client",
"children":[
{
"id":10,
"name":"Project one",
"amount":41524.759999999995,
"type":"project",
"children":[
{
"id":1,
"type":"cost",
"name":"Design",
"amount":15514.439999999999,
"children":[
{
"id":3,
"type":"cost",
"name":"Digital Design",
"amount":7461.54,
"children":[
{
"id":5,
"type":"cost",
"name":"Web Design",
"amount":3620.45,
"children":[
]
},
{
"id":6,
"type":"cost",
"name":"App Design",
"amount":3841.09,
"children":[
]
}
]
},
{
"id":4,
"type":"cost",
"name":"Print Design",
"amount":8052.9,
"children":[
]
}
]
}
]
}
]
}
我是 Laravel 雄辩的新手,无法编写查询,谁能帮助我?
解决方案
推荐阅读
- javascript - 反应钩子:useState嵌套了其他useState,setState不起作用?
- graph - 获得具有公共节点的两个节点之间的最长路径
- encoding - 多状态因变量编码
- flutter - 如何在 Scaffold 中添加另一个按钮?
- java - 如何通过 Google Pay API 在 NODEMCU 上验证在 google pay 中进行的付款交易?
- sql - 与 SQL Server 的连接突然停止工作
- r - 在 R 中使用 deparse 进行强制评估
- python - 总和的梯度是否等于pytorch中神经网络的梯度总和?
- c# - 使用 Unity 注入启动的对象
- javascript - NodeJs中的倒计时问题