Change cell color according to the result?

Asked

Viewed 636 times

4

I am a beginner in this universe, and I am locked in my development into a simple function that I cannot understand. This code below gets a value from the database, and I would like in the color cell, the background to change as 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>

1 answer

2


Put the code in your tr asking the field (was placed $row->cor, but you can change that) and whether the cor == 1 he puts 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>
  • 1

    Thank you friend, I managed to advance in my development thanks to you, I only had to make this slight change so that it works only in the specific line <tbody> @foreach($stocks as $Row) <tr> <th Scope="Row">{{ $Row->id }}</th> <td>{{ $Row->category->name }}</td> <td<? php if ($Row->color == 2) {echo ' style="background-color:green;"';}? >>{{ $Row->cor }}</td> <td>{{ $Row->product }}</td> <td>{{ $Row->brand }}</td> <td>{{ $Row->Qtd }}</td> <td>{{ $Row->observation }}</td>#Xa; </>tr @endach

  • @leonardosilva blz!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.