Change cell color according to result?

4

I am a beginner in this universe, and I am caught up in my development in a simple function that I can not understand. This code below gets a value from the database, and I would like the background cell to change by value, for example if the field for = 1 then the cell will be green .

  <tbody>
    @foreach($estoques as $row)

    <tr>
      <th scope="row">{{ $row->id }}</th>
      <td>{{ $row->categoria->nome }}</td>
      <td>{{ $row->cor }}</td>
      <td>{{ $row->produto }}</td>
      <td>{{ $row->marca }}</td>
      <td>{{ $row->qtd }}</td>
      <td>{{ $row->observacao  }}</td>

    </tr>
    @endforeach
  </tbody>

    
asked by anonymous 16.01.2017 / 23:16

1 answer

2

Put the code in your tr by asking the field ( was placed $row->cor , but you can change it ) and if cor == 1 a style in tr .

<tbody>
    @foreach($estoques as $row)
    <tr>

      <th scope="row">{{ $row->id }}</th>
      <td>{{ $row->categoria->nome }}</td>
      <td<?php if ($row->cor == 2) {echo ' style="background-color:green;"';}?>>{{ $row->cor }}</td>
      <td>{{ $row->produto }}</td>
      <td>{{ $row->marca }}</td>
      <td>{{ $row->qtd }}</td>
      <td>{{ $row->observacao  }}</td>

    </tr>
    @endforeach
</tbody>
    
16.01.2017 / 23:26