简体   繁体   English

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

[英]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.

相关问题 Laravel 雄辩,根据Column 值创建集合 - Laravel eloquent, create collection based on Column value 如何使雄辩地将其子集合推入其父集合? - How to make Eloquent push a child Collection inside its parent Collection? Laravel Eloquent - 如何使用 Eloquent 只获得每个父母的 2 个孩子? - Laravel Eloquent - how to get only 2 child of each parent using Eloquent? 如何从集合创建 Laravel Eloquent 模型? - How to create a Laravel Eloquent Model from Collection? Laravel Eloquent - 根据子关系属性排序父 - Laravel Eloquent - sorting parent based on child relationship attribute 如何基于 Laravel 中的另一个集合比较和更新 Eloquent 集合 - How to compare and update an Eloquent Collection based on another Collection in Laravel Laravel Eloquent Relationship: How to get parent of parent information from child using Laravel eloquent model relationship? - Laravel Eloquent Relationship: How to get parent of parent information from child using Laravel eloquent model relationship? 如何对laravel eloquent子关系进行排序并获取有序的父数据 - How to sort laravel eloquent child relation and get the ordered parent data 你如何在laravel雄辩中查询孩子和父母 - How do you query a child and parent in laravel eloquent Laravel 5.1 Eloquent:如何根据某些条件检索集合? - Laravel 5.1 Eloquent: How to retrieve a collection based on some conditions?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM