Search code examples
multidimensional-arraylaravel-8eloquent-relationshipphp-7.4

How can i get the values in eloquent relation array result of laravel 8


I have a result array from laravel8 relations. like below

$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,
       
         }
  
       ]
   }

When I print $val['q_text'] // output 1111 when I print $val['que_logic_relation'] //no result or empty I want to print the data in que_logic_relation seperately. How can I do that?


Solution

  • Issued fixed by adding toArray() to the query result and everything works fine now.