[英]How to create a parent > child collection with laravel based on an eloquent result?
Basically I have a eloquent result like this.基本上我有一个像这样的 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
}
For each line, I need to do a test to output a verification result (comparison of "operator" and "value" with the raw result of checkRule($url_id, ..) ) which I run at each turn of the loop.对于每一行,我需要对 output 进行测试,验证结果(“运算符”和“值”与 checkRule($url_id, ..) 的原始结果的比较),我在循环的每一轮运行。
I need to turn into a parent-child collection of this type我需要变成这种类型的父子集合
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
]
Then I could go into blade and send an email of the checkup.然后我可以将 go 放入刀片并发送检查的 email。
Is this possible?这可能吗? If so how?
如果有怎么办? I have tried everything but have not succeeded.
我已经尝试了一切,但没有成功。
Thank you very much.非常感谢。
as i know you must use api resource class to change output of eloquent据我所知,您必须使用 api 资源 class 来更改 Z4B4D28FC143CA3438E48631AFF6Z1 的 output
https://laravel.com/docs/8.x/eloquent-resources https://laravel.com/docs/8.x/eloquent-resources
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.