Search code examples
phplaravellaravel-5.3laravel-blade

Dinamic Check Box + Table With Blade Famework and Laravel


I need to organize my checkbox fields in table lines.

I want every 10 items the blade breaks the table row.

Here is my code:

<table>

  <div class="btn-group" data-toggle="buttons">
    {{$i = 0}}

    @foreach($sintese as $s)
        <tr>
            <td>
                <label class="btn btn-primary">
                    <input type="checkbox" autocomplete="off" name="chksintese" id="{{$s->cod_sintese_conversa}}">
                    <span class="glyphicon glyphicon-ok"></span>
                    {{$s->descricao}}
                </label>
            </td>

            @if ($i > 10)
                {{'</tr>'}}
                {{$i = 0}}  
            @else
                {{$i++}}
            @endif

        @endforeach
    </div>

</table>

And Here is My Result:


Solution

  • What about:

    <table>
        <div class="btn-group" data-toggle="buttons">
            <tr>
                @foreach($sintese as $s)
                    <td>
                        <label class="btn btn-primary">
                            <input type="checkbox" autocomplete="off" name="chksintese" id="{{$s->cod_sintese_conversa}}">
                            <span class="glyphicon glyphicon-ok"></span>
                            {{$s->descricao}}
                        </label>
                    </td>
    
                    @if ($loop->iteration % 10 == 0 && !$loop->last)
                        </tr><tr>
                    @endif
                @endforeach
            </tr>
        </div>
    </table>