我在laravel刀片中有两个forlolo,这就是为什么它给我两次每条记录。
@foreach($notes = $notes->sortBy(function ($note) {
return ($note->active ? '0' : '1') . ($note->status('health') == 'down' ? '0' : '1') . ($note->status('speed'));
}); as $notification)
@foreach ($notification->statuses as $timestamp)
<tr>
<td> {{ $notification->website_url }} </td>
@if($notification->status('health') == 'up')
<td> {{ $notification->status('health') }} <span class="up"></span>.<br><span class="timestamp_green">{{$timestamp->pivot->created_at }}</span></td>.
@elseif($notification->status('health') == 'down')
<td> {{ $notification->status('health') }} <span class="down"></span>.<br><span class="timestamp_red">{{$timestamp->pivot->created_at }}</span></td>
@else
<td> {{ $notification->status('health') }} <span class="unsigned"></span>.<br><span class="timestamp_unsigned">{{$timestamp->pivot->created_at }}</span></td>
@endif
@if((int)$notification->status('speed'))
@if($notification->status('speed') <= 59)
<td> {{ $notification->status('speed') }} <span class="down"></span>.<br><span class="timestamp_red">{{ $timestamp->pivot->created_at }}</span></td>
@elseif($notification->status('speed') >=60 && $notification->status('speed') <= 79)
<td> {{ $notification->status('speed') }} <span class="improve"></span>.<br><span class="timestamp_improve">{{ $timestamp->pivot->created_at }}</span></td>
@elseif($notification->status('speed') >= 80)
<td> {{ $notification->status('speed') }}<span class="up"></span>.<br><span class="timestamp_green">{{ $timestamp->pivot->created_at }}</span></td>
@endif
@else
<td> {{ $notification->status('speed') }} <span class="unsigned"></span>.<br><span class="timestamp_unsigned">{{ $timestamp->pivot->created_at }}</span></td>
@endif
<td>
{{ $notification->active == 1 ? 'Yes' : 'No' }}
</td>
<td>
@if (Auth::user()->hasRole('aileen'))
<a href="{{ route('notifications.edit', [$notification->id]) }}">
<input type="submit" name="edit" value="edit"/>
</a>
@endif
<a href="{{ route('history',[$notification->id]) }}">
<input type="submit" name="history" value="history"/>
</a>
</td>
</tr>
@endforeach
@endforeach
</tbody>
一个人给了我一个更好的方法吗?我的第二个foreach循环访问pivotote表中的数据或时间戳。