如何找到我的 table 中剩余字段的值在 laravel 中大于零的行

how to find the rows of my table in which the value of remaining field is more than zero in laravel

我有一个布局显示所有订单,其中我也有支付和剩余金额的记录,所以如果剩余字段数据大于 0,我试图将行的背景颜色显示为红色我正在尝试这个方法

public function noBalance() {

    return Order::where('remaining', '>', 0)->first();
}

我正在订单的模型文件中创建这个 也试过这个

return Order::where('remaining', '>', 0);

  @foreach ($orders as $order)
          
       <tr style="{{ $order->noBalance() ? 'background-color: lightcoral;' : '' }}">
            (here i am using that function in my allorder.blade.php)                
          <td>{{$order->id}}</td>
          <td>{{$order->client}}</td>
          <td>{{$order->salesmanRelation->employee_name}}</td>
          <td>{{$order->orderBooker->employee_name}}</td>
          <td>{{$order->total_amount}}</td>
          <td>{{$order->paid}}</td>
          <td>{{$order->remaining}}</td>
          <td>{{$order->discount}}</td>
          <td>{{$order->created_at->toFormattedDateString()}}</td>
          <td><a href="/orders/{{$order->id}}">Detail</a></td>
          <td><a href="/orders/{{$order->id}}/edit">Edit</a></td>
      </tr>                        
     
   @endforeach

但是在使用这个之后,我的 table 的所有行都得到浅色珊瑚,而不仅仅是剩余的 >0

的行

请帮忙!

如果您的数据库中有字段 'remaining',您可以通过以下方式访问它:

$order->remaining;

因此您的 if 语句应如下所示:

{{ $order->remaining > 0 ? 'background-color: lightcoral;' : '' }}

并且可以删除函数 noBalance()。 是的,这是正确的答案