Vasilis Greece Vasilis Greece - 5 months ago 43
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)
<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>

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


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


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