Vasilis Greece Vasilis Greece - 26 days ago 11
jQuery Question

Foreach output dynamic variable outside of loop - Laravel

I use Laravel version 5.1 and I need ideas how to output a specific dynamic variable(data-target) outside of foreach.

The modal div(bootstrap modal) it must be outside of foreach!

What is the best to use php or jquery and how to solve this problem?

Html and Laravel(php):

@foreach ($category as $name => $value)
<li>
<a href="">{{$value->category_name}}</a>
<button type="button" class="btn btn-warning fa fa-pencil-square-o pull-right easy" data-toggle="modal" data-target="#{{$value->id}}"></button>
...
</li>
@endforeach

<div class="modal fade" id="{{$value->id}}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
...
</div>

Answer

I found the solution. No AJAX required or additional foreach(to prevent heavy loaded html data). It works perfectly!

jquery:

$(document).ready(function(){
    $("#categoryview .fa-pencil-square-o").click(function(){
        $(this).removeAttr("data-target").attr("data-target", "#edit");
    });
});
Comments