How to get the element data of array? Below is my array data of object Tour.
Some Tour might not have tour_attendees (empty array).
And there will be ONLY TWO records (attendees) for ONE TOUR.
#items: array:3 [▼
0 => {#2115 ▶}
1 => {#3067 ▶}
2 => {#2125 ▼
+"id": 12
+"schedule_date": "28-11-2021"
+"created_at": "2021-11-18T00:16:42.000000Z"
+"updated_at": "2022-01-19T08:29:05.000000Z"
+"deleted_at": null
+"tour_attendees": array:2 [▼ // array data that I want to extract
0 => {#3077 ▶} // attendee #1
1 => {#3054 ▶} // attendee #2
]
}
I want to extract the data and put inside the table as below.
| No | Attendee #1 | Mobile | Attendee #2 | Mobile |
| | | (Attendee #1) | | (Attendee #2) |
|-----|----------------|-----------------|------------------|-----------------|
| 1 | | | | |
| 2 | | | | |
Blade file
@foreach ($tour->tour_attendees as $key => $value)
<td>
@if (!empty($tour->tour_attendees))
@foreach ($tour->tour_attendees as $key => $attendee)
@if ($key == 0)
{{ $attendee->name }}
@endif
@endforeach
@endif
</td>
<td> attendee #1 mobile</td>
@endforeach