Skip to content
Advertisement

Laravel, How to view array in foreach loop

I want to view the loop of array in blade view, in my view i want print the array items. I tried with this but it doesn’t work

               <div class="time-picker-container">
                                <div class="time-picker">
                                    <ul>
                                       @foreach($slots as $key => $slot) 
                                          <li>
                                            <label class="time-picker-toggle-wrapper">
                                                <input type="radio" value="" name="time-picker" />
                                                <span class="time-name">{{ $slot->value }}</span>
                                            </label>
                                        </li>
                                       @endforeach
                                    </ul>                                       
                                </div>
                            </div>

the array:

     array:55 [▼
        0 => array:2 [▼
          "value" => "08:15"
          "time-name" => "08:15 AM"
        ]
        1 => array:2 [▼
          "value" => "08:30"
          "time-name" => "08:30 AM"
        ]
        2 => array:2 [▼
          "value" => "08:45"
          "time-name" => "08:45 AM"
        ]
        3 => array:2 [▼
          "value" => "09:00"
          "time-name" => "09:00 AM"
        ]

Advertisement

Answer

It’s an array not object so you need to do {{ $slot['value'] }} not {{ $slot->value }}

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement