Vasilis Greece Vasilis Greece - 1 year ago 88
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">

Answer Source

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");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download