I have a collection that brings me data from the station table, equipment table related to that station and the parameters that each team can measure. This is obtained through the relationships in the models.
Estacion
Equipo
Equipo_estacion
Parametro
Equipo_Parametro
I get a collection with the data Station> Team> parameter
in the controller I pass an ordered arrangement with the position and name of the parameters, this I compare with those obtained from the base
$param_header = array('MP10','MP25','SO2','NO2','CO','O3','BC');
and I want to load in the table every field where a station has a device that measures that parameter
the first data of the row loads it in the correct position, that is, in the station Bodega1, there is a device that measures the SO2 parameter and another that measures NO2, in the image NO2 it does not correspond with its corresponding column and the same thing it happens in some of the following rows.
@foreach($est_equi as $item1)
@foreach($item1->equipos as $equipo)
<tr>
<td>{{ $item1->region_id }} </td>
<td>{{ $item1->nombre .'-' . $item1->id }} </td>
@foreach($equipo->parametros as $key=>$param)
@php ($i = 0)
//Aca comprueba en que posicion dentro del arreglo esta el parametro
{!! $posicion = array_search($param->nombre, $param_header) !!}
{{ 'Las posicion es :' .$offset }}</br>
@while ($i < 7)
@if($i == $posicion)
<td>{{ $param->nombre}} </td>
@break;
@else
<td> no </td>
@endif
@php ( $i++ )
@endwhile
@endforeach
</tr>