【问题标题】:How can i get the values in eloquent relation array result of laravel 8如何获取 laravel 8 雄辩关系数组结果中的值
【发布时间】:2021-03-17 07:19:24
【问题描述】:

我有一个来自 laravel8 关系的结果数组。如下所示

$val = {
         "q_id": 1,
         "q_text": "1111",
         "q_mandatory": 1,
         "q_status": "unpublished",
         "que_logic_relation": [
         {
           "ql_id": 1,
           "ql_quest_id": 1,
           "ql_answer_choice_id": null,
           "ql_succeeding_q_order": 3,

         },
         {
           "ql_id": 4,
           "ql_quest_id": 1,
           "ql_answer_choice_id": null,
           "ql_succeeding_q_order": 3,
       
         }
  
       ]
   }

当我打印 $val['q_text'] // 输出 1111 当我打印 $val['que_logic_relation'] //没有结果或为空时 我想单独打印 que_logic_relation 中的数据。我该怎么做?

【问题讨论】:

  • 这不是一个有效的php代码,你的意思是你的值是json?如果是这样,请使用$val = json_decode($resultArray,true);

标签: multidimensional-array laravel-8 eloquent-relationship php-7.4


【解决方案1】:

通过将 toArray() 添加到查询结果已解决问题,现在一切正常。

【讨论】:

    猜你喜欢
    • 2020-12-02
    • 2018-04-13
    • 1970-01-01
    • 2018-09-20
    • 2016-06-09
    • 2021-12-15
    • 2019-07-16
    • 1970-01-01
    • 2018-11-12
    相关资源
    最近更新 更多