How show image in a bootsrap modal How can I open a modal to view the image? Here is my code:
<div class="fluid-container">
<div class="container">
<h1 class="text-center mt-5 mb-5 h1-title">Our Gallery</h1>
<div class="row d-flex">
@if(count($files) > 0)
@php $id=0;@endphp
@foreach($files as $file)
@php $id++;@endphp
<div class="col-xl-4 col-sm-6 p-1"><img class="btn p-0 card-img3" src="{{$file->image}}"></div>
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Launch demo modal
</button>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
...
</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>
@endforeach
@else
@endif
</div>
</div>
</div>
</div>
Just put your loop for images and further content inside of the class "modal-body".
Another tip, Laravel provides the $loop variable inside of a @foreach , so you do not need to do $id++;
Just use $loop->index and it will give you the same number.
https://laravel.com/docs/7.x/blade#the-loop-variable
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
@foreach($files as $file)
<img class="btn p-0 card-img3" src="{{$file->image}}">
@endforeach
</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>
You are doing that wrong. I have some images and I am showing them normally here is a link https://snipboard.io/NEs57g.jpg . On click on an image, I want to show the image in model not all image.
Please sign in or create an account to participate in this conversation.