Is it possible to add the results in a datediff in a foreach loop? I am showing a page for time clock punches and want to add each shift in the end to display the total hours for the pay period. I had tried a few things from searching around and nothing came anywhere to fruition. I am not even sure that I am on the right path on how to complete this. If I am way off please point me in the right direction so I may learn the right process to take.
@foreach($punches as $row)
<tr>
<?php $start= date_create($row->time_in);
$end= date_create($row->time_out)
?>
<td>{{date_format($start, "m-d-Y H:i")}}</td>
@if($row->time_out === NULL)
<td>
{!! Form::open(['url' => route('timeclock.update', $row->id), 'method' => 'POST']) !!}
@method('PUT')
@csrf
{{ Form::hidden('time_out', date('Y-m-d H:i:s')) }}
<button type="submit" class="btn btn-outline-warning btn-rounded waves-effect">Clock Out</button>
{!! Form::close() !!}
</td>
@else
<td>{{date_format($end, "m-d-Y H:i")}}</td>
@endif
@if($row->time_out === NULL)
<td>Calculation Pending</td>
@else
<?php
$interval = $start->diff($end);
?>
<td>{{$interval->format('%h Hours %i minutes')}}</td>
@endif
</tr>
@endforeach