如何根据雄辩的结果使用 laravel 创建父>子集合?



基本上我有一个像这样雄辩的结果。

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
}

对于每一行,我需要做一个测试来输出验证结果("运算符"one_answers"值"与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
]

然后我就可以进入blade并发送一封检查的电子邮件。

这可能吗?如果是,怎么办?我什么都试过了,但没有成功。

非常感谢。

正如我所知,您必须使用api资源类来更改雄辩的输出

https://laravel.com/docs/8.x/eloquent-resources

最新更新