The problem I have is that I use a modal
to edit the projects, so when I have more than 2 (projects), when I inspect the code I realize that the modal is repeated for each project, which I would like to avoid and only show the one I am going to to edit.
that is, to have only 1 modal
and that when I click the button to open it, modal
I get the values of that project so that it is not generated several times.
That's possible?
projects(BLADE):
@foreach ($proyectos as $proyecto)
<div class="card">
<!-- NOMBRE PROYECTO -->
<div class="card-header">
<div>{{$proyecto->proy_nombre}}</div>
<!-- Editar -->
<div >
<a data-toggle="modal" data-target="#EditarProyecto{{$proyecto->proy_id}}" href=""><i class="fa fa-pen"></i></a>
</div>
</div>
<!-- DESCRIPCION PROYECTO -->
<div class="card-body">{{$proyecto->proy_descripcion}}</div>
</div>
@include('modal.modal_editar_proyecto')
@endforeach
modal_edit_project (BLADE) :
<div class="modal fade" id="EditarProyecto{{$proyecto->proy_id }}" role="dialog" aria-labelledby="EditarPryectoModal" aria-hidden="true">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
{{$proyecto->proy_nombre}}
</div>
</div>
</div>
I would create my Modal outside of the loop, so that it would be armed only once, then I would pass the data to the dat-* variables, for example, data-target, it would only be EditProject, then another that would be data-idproject, and that would be taken with javascript, it would be something like this;
Then the Modal;
And lastly, I handle it with Javascript;
Perhaps there are more optimal or elegant ways to do it, but I would do it this way.