Reputation: 5
i have a layout that shows all the orders placed in which i have record of paid and remaining amount also , so i am trying to display the background color of rows as red if remaining field data is more than 0 for this i am trying this method
public function noBalance() {
return Order::where('remaining', '>', 0)->first();
}
i am creating this in model file of Order also tried this
return Order::where('remaining', '>', 0);
and
@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
but after using this all the rows of my table gets light coral not only the rows with the remaining >0
please help!
Upvotes: 0
Views: 45
Reputation: 36
If there is a field 'remaining' in your database you can access it with:
$order->remaining;
So your if statement should look like this:
{{ $order->remaining > 0 ? 'background-color: lightcoral;' : '' }}
And the function noBalance() can be removed. yes that is the right answer
Upvotes: 1