Good, I'm trying to go through a foreach that I have separated by categories where I show brief descriptions of each category inside. The title always gives me the same title and I can't go through it correctly. I leave you the code so you can take a look at what it is failing me that there will be several things for sure.
<div class="row">
@foreach($categoria as $listado1)
<div class="col xl4 m4 s12">
<div class="card deep-purple lighten-2 z-depth-3">
<div class="card-image waves-effect waves-block waves-light">
<a class="modal-trigger" href="#modal4"><img class="activator" src="http://backend.imaginarqultural.es:81/storage/{{ $listado1->url }}" alt="{{ $listado1->name }}"></a>
</div>
<div class="card-content">
<span class="card-title activator grey-text text-lighten-4">{{ $listado1->titulo }}</span>
</div>
</div>
</div>
@endforeach
<!-- Modal Structure -->
@foreach($categoria as $listado1)
<div id="modal4" class="modal">
<div class="modal-content grey lighten-4">
<h4>{{ $listado1->titulo }}</h4>
@foreach($portfolio as $listado2)
@if($listado2->category_id == $listado1->id)
<p>{{ $listado2->actividad }}, {{ $listado2->lugar }}<p>
@endif
@endforeach
</div>
<div class="modal-footer grey lighten-4">
<a href="#!" class="deep-purple lighten-3 modal-action modal-close waves-effect waves-purple btn-flat yellow-text text-accent-1">Aceptar</a>
</div>
</div>
@endforeach
</div>
</div>
You are putting the modals and the link to open them inside a foreach (two actually, but for this case it is the same), so all your modals are going to have the same id
what is not allowed in html https://developer.mozilla.org/es/docs/Web/HTML/Global_Attributes/id .
And also all the links also point to the same modal
One way around this can be by adding the value of
$loop->iteration
(The current iteration of the loop https://laravel.com/docs/5.8/blade#the-loop-variable ) to the id of each modal, to make it unique, and by Of course, you'll also have to do it in the href of the link to open each modal. For example:I removed the tags that are not relevant to make it easier to see what the point of what I am saying is. In your code you should only add
{{ $loop->iteration }}
theid
one for the modals and the onehref
for the links.As a note, 2 foreach are not necessary, you can also put the modal in the foreach you already have: