lundi 21 novembre 2016

laravel: double foreach loop retruns a record twice?

I have two for eachloop in laravel blade, that is why it give me each record two times.

@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>  </td>
                @if($notification->status('health') == 'up')
                    <td>  <span class="up"></span>.<br><span class="timestamp_green"></span></td>.
                @elseif($notification->status('health') == 'down')
                    <td>   <span class="down"></span>.<br><span class="timestamp_red"></span></td>
                @else
                    <td>   <span class="unsigned"></span>.<br><span class="timestamp_unsigned"></span></td>
                @endif 
                @if((int)$notification->status('speed'))
                    @if($notification->status('speed') <= 59)
                        <td>  <span class="down"></span>.<br><span class="timestamp_red"></span></td>
                    @elseif($notification->status('speed') >=60 && $notification->status('speed') <= 79)
                        <td>  <span class="improve"></span>.<br><span class="timestamp_improve"></span></td>
                    @elseif($notification->status('speed') >= 80)
                        <td> <span class="up"></span>.<br><span class="timestamp_green"></span></td>
                    @endif
                @else
                    <td>  <span class="unsigned"></span>.<br><span class="timestamp_unsigned"></span></td>       
                @endif
                <td>                         
                    
                </td>
                <td>
                    @if (Auth::user()->hasRole('aileen'))
                        <a href="">
                            <input type="submit" name="edit" value="edit"/>
                        </a>
                    @endif
                    <a href="">
                        <input type="submit" name="history" value="history"/>
                    </a>
                </td>
            </tr>
        @endforeach
    @endforeach 
</tbody>

one one gave give me a better way to do it? my second foreach loop to access the data or timestamp in the pivote table.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire