lundi 22 avril 2019

How to view the grandchild of an an array in Blade using laravel?

I am trying to fetch the results of the grandchild of an array and display it in the Blade. There are two arrays:-

  array:2 [▼
  "Block A" => array:49 [▶]
  "Flat C" => array:100 [▶]
  ]

As there are 2 arrays Block A and Flat C and each there are few more arrays.

  array:2 [▼
    "Block A" => array:49 [▼
        1 => array:1 [▶]
        2 => array:1 [▶]
        3 => array:1 [▶]
        4 => array:1 [▶]
        ...
        ...

     "Flat C" => array:100 [▼
         50 => array:1 [▶]
         51 => array:1 [▶]
         52 => array:1 [▶]
         53 => array:1 [▶]
         54 => array:1 [▶]
        ...
        ...

And now in these arrays, I have some value that I want to fetch and display it on the Blade. The values of each grandparent are:-

   array:2 [▼
     0 => []
     "Block A" => array:49 [▼
        1 => array:1 [▼
        "Block A" => "1"
     ]
        2 => array:1 [▼
        "Block A" => "2"
     ]
        3 => array:1 [▼
        "Block A" => "3"
     ]
        4 => array:1 [▼
        "Block A" => "4"
     ]
        5 => array:1 [▼
        "Block A" => "5"
        ...
        ...

     "Flat C" => array:100 [▼
        50 => array:1 [▼
           "Flat C" => "1"
      ]
        51 => array:1 [▼
        "Flat C" => "2"
      ]
        52 => array:1 [▼
        "Flat C" => "3"
      ]
        53 => array:1 [▼
        "Flat C" => "4"
      ]
        54 => array:1 [▼
        "Flat C" => "5"
      ]
        ...
        ...

This values are coming from the database in the foreach loop.

return view('admin.home')->with('roomNums', $qr_RoomNums);

at the moment, in the blade, I have:-

@foreach ($roomNums as $key1 => $value1)
   @foreach ($value1 as $key2 => $value2)
      @foreach ($value2 as $key3 => $value3)
         <option value="">  </option>
       @endforeach
     @endforeach
@endforeach

The logic is, this will show that Block A has this many rooms and Flat C has this rooms. The results what I am getting here now, on each selectboxs, I am getting both the values of Block A and Block C displayed. Where as I wanted to display 49 Rooms for Block A and 100 for Flat C as seen on the dd(); example above.

Not too sure what I am doing wrong here and how to fix this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire