How to display 0 but not empty string values or null in Laravel

Categorized as Laravel

There is a beautiful filled() method in Laravel so that you can avoid unnecessary outputs in your rendering blade-templates. Here is the example:

@if (filled($product->fat))
<tr>
  <td>Fat</td>
  <td>{{ $product->fat }}</td>
</tr>
@endif
Quantity per serving
Energy1438 kJ / 338 kcal
Protein0
Fat0
Carbohydrate85

See the official documentation.

Thnx to Daniel Eckermann.

Leave a reply

Your email address will not be published. Required fields are marked *