samedi 26 décembre 2020

Laravel Multiple @foreach in View

@foreach($data as $var)
    <tr>
        <td style="text-align:center;">
          <input type="checkbox" id="select" class="sub_chk" data-id="" value="" name="selected_values[]"/>
        </td>
        <td></td>
        <td></td>
        <td></td>
        <td> 
          <?php $elements = array(); ?>
          @foreach($var->student_registrars as $category)
            <?php $elements[] = '<a href=" '.route('student-registrars.show', $category->id).' "> '.$category->name.' </a>'; ?>
          @endforeach
          <?php echo implode(',<br>', $elements); ?>
        </td> 
        <td>
          // Second foreach should be here
        </td>
        <td>
          <a href="" class="btn btn-primary btn-sm">Detail</a>
        </td>
    @endforeach 

    // Second foreach
    @foreach($dataGM as $var2)
    <tr>
       <td>
         <?php $elements = array(); ?>
         @foreach($var2->student_registrars as $category)
            <?php $elements[] = '<a href=" '.route('student-registrars.show', $category->id).' "> '.$category->name.' </a>'; ?>
         @endforeach
         <?php echo implode(',<br>', $elements); ?>
       </td>
    </tr>
    @endforeach 

      </tr>

And the result for code above is: enter image description here

I have a little problem related multiple foreach in one view. It's actually just a simple problem but I am stuck here. Any body can solve it? Should I use partial view to do this?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3aJ9GLe
via IFTTT

Aucun commentaire:

Enregistrer un commentaire