How to add class to tr in table using foreach in laravel

Updated at 19-Apr-2021, By samar

How to add class to tr in table using foreach in laravel

Hello everyone, in this post we will look at how to solve "How to add class to tr in table using foreach in laravel" in programming.

  • Add class to tr in table with even and odd number

    --PATH resources\views\<yourfile>.blade.php
    //Add class to odd tr
    <tr class="@if($loop->odd) bg-danger @endif">
    
    // Add class to even tr
    <tr class="@if($loop->even) bg-danger @endif">
    

    You can add class to tr in the table using foreach in laravel using this code snippet. This code snippet basically helps you to add class to every tr on the basis of even and odd order.

Back to code snippet queries related laravel