How can I pass parameter to modal on the laravel 5.3?

Viewed 343

My view is like this :

<table class="table table-bordered">
    ...
    <tr>
        @for($i = 0; $i < 5; $i++) 
        <td id="image-view-li-{{$i}}" style="display: none" data-toggle="modal" data-target="#modal-option">
            <img id="image-view-{{$i}}" src="https://myshop.co.id/img/shop1.jpg" alt="">
        </td>

        @section('modal')
        @include('components.modal.option',['i'=>$i]) 
        @endsection
        @endfor
    </tr>
    ...
</table>

When I click the td, it will call modal

My modal is like this :

<div id="modal-option" class="modal" tabindex="-1" role="dialog">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div class="form-horizontal">
                    <div class="form-group">
                        <a href="javascript:" id="image-edit-{{$i}}">
                            <span class="fa fa-pencil"></span>
                        </a>
                    </div>
                    <div class="form-group">

                        <a href="javascript:" class="text-danger" id="image-delete-{{$i}}">
                            <span class="fa fa-trash"></span>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

I want to pass parameter $i to modal

For example, I click td that have $i = 3. Then it will pass paramter $i = 3 to modal

I had try it like my above code

But, $id sent is always 0

How can I solve this problem?

Update

I had find solution

@for($i = 0; $i < 5; $i++) 
<td id="image-view-li-{{$i}}" style="display: none" data-toggle="modal" data-target="#modal-option-{{$i}}">
    <img id="image-view-{{$i}}" src="https://myshop.co.id/img/shop1.jpg" alt="">
</td>
@include('components.modal.option',['i'=>$i]) 
@endfor


<div id="modal-option-{{$i}}" class="modal" tabindex="-1" role="dialog">
    ...
</div>

It works

2 Answers
Related