Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Dynamic Bootstrap Tables Columns Foreach

Hi Team,
Actually I just Wanted to Render Data Like
Expecting Values like Given Below:-

enter image description here

But Coming Values Like Given Below:-

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

** Im Using this in my Laravel Project Here Is My Code:-**

<table class="table table-striped table-bordered">
<thead>
    <tr>
      <th scope="col">Skills</th>
      <th scope="col">Abilities</th>
      <th scope="col">Work Value</th>
      <th scope="col">Work Context</th>
    </tr>
</thead>
<?php
    $sub_skill = ["Skill 1","skill 2"];
    $sub_abilities = ["Ability 1","Ability 2","Ability 3","Ability 4","Ability 5","Ability 6"];
    $sub_workactivity = ["workactivity 1","workactivity 2"];
    $sub_workcontext = ["workcontext 1","workcontext 2", "workcontext 3"];
?>
<tbody>
    @foreach($sub_skill as $skill_key=>$skill_value)
           <tr>
               <td>{{ $skill_value }}</td>
               <td></td>
               <td></td>
               <td></td>
           </tr>
    @endforeach
       @foreach($sub_abilities as $abilities_key=>$abilities_value)
           <tr>
             <td></td>
             <td>{{ $abilities_value }}</td>
             <td></td>
             <td></td>
           </tr>
       @endforeach
       @foreach($sub_workactivity as $sub_workactivity_key=>$sub_workactivity_value)
           <tr>
             <td></td>
             <td></td>
             <td>{{ $sub_workactivity_value }}</td>
             <td></td>
           </tr>
       @endforeach
       @foreach($sub_workcontext as $workcontext_key=>$workcontext_value)
           <tr>
             <td></td>
             <td></td>
             <td></td>
             <td>{{ $workcontext_value }}</td>
           </tr>
       @endforeach
</tbody>

Please Help me.
Thanks Team

>Solution :

You need one loop and each iteration is one row. So calculate the maximum length of all collections and use a for loop with this length.

//pseudo code
@foreach($i=0; $i<$max_length; $i++)
       <tr>
           <td>{{ isset($sub_skill[$i]) ? $sub_skill[$i] : '' }}</td>
           <td>{{ isset($sub_abilities[$i]) ? $sub_abilities[$i] : '' }}</td>
           <td>{{ isset($sub_workactivity[$i]) ? $sub_workactivity[$i] : '' }}</td>
           <td>{{ isset($sub_workcontext[$i]) ? $sub_workcontext[$i] : '' }}</td>
       </tr>
@endforeach
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading