I want to change color to Red when updating status as Re-order level in laravel 8. how i do that?

This is productObserver.

public function updating(product $product)
  {
   
   if ($product->Qty <= $product->ReOrderLevel){
      $product->Status='Reorder level';}

   else if ($product->Qty >$product->ReOrderLevel ){
      $product->Status='In Stock';}  

   if ($product->Qty <= 0) {
      $product->Status = 'Out of Stock';}
  
  }

This is product view. It displays all details of the product and the Status of the product. Here, I want to display status in red colour when status changes into re-order level.

<table>
            <tr >
              <th >@sortablelink('Name')</th>
              <th >Product View</th>
              <th >Brand</th>
              <th >@sortablelink('Price')</th>
              <th >@sortablelink('Qty')</th>
              <th>Stock_Defective</th>
              <th >Status</th>
              <th >Action</th>
            </tr>
            @foreach($products as $product)
            <tr>                                                
              <td>{{$product['Name']}}</td>
              <td> <img src="{{asset('uploads/product/'.$product->image)  }}"
              class="img-circle" width="100px;" height="100px;" alt="Product-Image">  </td>
              <td>{{$product['Brand']}}</td>
              <td>{{$product['Price']}}</td>
              <td>{{$product['Qty']}}</td>
              <td>{{$product->stock_defective}}</td>
              <td>{{$product['Status']}}</td>
     
            </tr>
                @endforeach
          </table>
How I change text colour to red when updating product status as Reorder level ?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You can add inline style with condition

in blade

<td @if($product['Status'] =='Reorder level')  style="color: red;" @endif>{{$product['Status']}}</td>

use @if($product['Status'] =='Reorder level') style="color: red;" @endif

Method 2

Ternary operator will do the job at laravel blade.

yourfile.blade.php

<p class="{{ $product->Status == 'Reorder level' ? 'red' : '' }}"> some text </p>

your.css

.red { color: red }


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x