[英]How to create a parent > child collection with laravel based on an eloquent result?
基本上我有一个像这样的 eloquent 结果。
99 => {#2033
+"rule_id": 2
+"user_id": 1
+"url_id": 50
+"operator": "<="
+"value": "3"
+"id": 2
+"titre": "Temps de réponse"
+"description": "Description 2"
+"actived": 1
+"type": "float"
+"unit": "seconde(s)"
+"created_at": "2022-01-24 18:58:45"
+"updated_at": "2022-01-24 18:58:45"
+"category_id": 2
}
100 => {#2034
+"rule_id": 1
+"user_id": 1
+"url_id": 51
+"operator": "="
+"value": "Indexable"
+"id": 1
+"titre": "Indexable"
+"description": "Description 1"
+"actived": 1
+"type": "bool"
+"unit": null
+"created_at": "2022-01-24 18:58:45"
+"updated_at": "2022-01-24 18:58:45"
+"category_id": 1
}
101 => {#2035
+"rule_id": 2
+"user_id": 1
+"url_id": 51
+"operator": "<="
+"value": "3"
+"id": 2
+"titre": "Temps de réponse"
+"description": "Description 2"
+"actived": 1
+"type": "float"
+"unit": "seconde(s)"
+"created_at": "2022-01-24 18:58:45"
+"updated_at": "2022-01-24 18:58:45"
+"category_id": 2
}
对于每一行,我需要对 output 进行测试,验证结果(“运算符”和“值”与 checkRule($url_id, ..) 的原始结果的比较),我在循环的每一轮运行。
我需要变成这种类型的父子集合
rules [
0 [
'id' => 1,
'title' => 'rule 1',
'check_ok' =>
[
0 => [
'address' => 'http://www...',
'operator' => '<='
'excepted' => '10'
'obtained' => '1'
],
1 ...
]
'check_nok' =>
[
0 => [
'address' => 'http://www...',
'operator' => '<='
'excepted' => '11'
'obtained' => '15'
],
1 ...
],
1 .... //rule 2
]
然后我可以将 go 放入刀片并发送检查的 email。
这可能吗? 如果有怎么办? 我已经尝试了一切,但没有成功。
非常感谢。
据我所知,您必须使用 api 资源 class 来更改 Z4B4D28FC143CA3438E48631AFF6Z1 的 output
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.