在模态多图像中没有正确显示laravel 5.3

时间:2017-01-02 09:52:47

标签: laravel twitter-bootstrap-3

我正在使用bootstrap模式来显示我的所有图像但在我的laravel 5.3项目中只显示一个图像我无法弄清楚如何在此代码下面修复它只有第一个图像显示如果我在最后使用@endforeach然后代码只显示最后一张图片。

<div class="col-lg-12">
@foreach($prizebond_images as $prizebond_image)
    <div class="col-lg-4">                                
       {!! Html::image('images/'.$prizebond_image->prizebond_image,'a picture',['class'=>'img-thumbnail img-responsive','data-target'=>"#myModal",'data-toggle'=>'modal']) !!}
        <p class="text-success">{{$prizebond_image->prizebond_image_rank}}</p>
    </div>
@endforeach

</div>
<!-- Modal -->

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body" width="auto" height="auto">
                {!! Html::image('images/'.$prizebond_image->prizebond_image,'a picture',['class'=>'img-thumbnail img-responsive']) !!}
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                <button type="button" class="btn btn-primary">Save changes</button>
            </div>
        </div>
    </div>
</div>

1 个答案:

答案 0 :(得分:1)

您还需要将模态窗口代码放在循环中。此外,您需要为每个模态和链接创建unqiue ID,为此使用the loop variable。例如:

@foreach($prizebond_images as $prizebond_image)
    ....      
    {!! Html::image(.... 'data-target' => "#myModal".$loop->index, 'data-toggle'....
    ....
    <!-- Modal -->
    <div class="modal fade" id="myModal{{ $loop->index }}" tabindex="-1"....
    ....
@endforeach