I am using nested foreach in my blade template, but all records are duplicated. So the code I've tried is the following.
<tbody>
@foreach($ordertaker as $ot)
@foreach($totalorder as $tord)
<tr>
<td>
{{ $ot->total_visit }}/{{ $tord }}
</td>
</tr>
@endforeach
@endforeach
</tbody>
if in db i have value
total_visit = [10, 30] and sum = [20, 40]
then i have output
10/20
10/20
20/40
20/40
but required result is
10/20
20/40
is there a way i can use single loop to get both result example
@foreach($ordertaker as $ot && $totalorder as $tord)
Try this, hope this would work you are using two loops so if you have 2 results then they would be multiplied that's why you are getting 4 results
<tbody>
@foreach($ordertaker as $key => $ot)
<tr>
<td>
{{ $ot->total_visit }}/{{ $totalorder[$key] }}
</td>
</tr>
@endforeach
</tbody>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.