Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

prince's avatar

Bootstrap modal edit form in laravel

My project have list of customers. I want to edit the customers. All forms using bootstrap modals. In my customers list i used :

a href="{{route('admin.customers.edit',$id)}}" data-hover="tooltip" data-placement="top" data-target="#modal-edit-customers" data-toggle="modal" id="modal-edit" title="Edit"

Above link using for edit each item. When i click the edit link, I get the response from controller and populate the modal edit form for one time. Later link not working. If i refresh the page, it will work again for one time. Anyone help me to find the issue?

0 likes
5 replies
Tiago's avatar

What was the solution, I have the same problem.

Ricardo's avatar

Hey @Tiago!

It happens that {{route('admin.customers.edit',$id)}}is only parsed when it is called from the Controller, so one time, the first time.

You should update the hrefwhen the edit link is clicked.

MaverickChan's avatar

you need to give each modal a unique id

try

the button:

<a href="{{route('admin.customers.edit',$id)}}" data-hover="tooltip" data-placement="top" data-target="#modal-edit-customers{{ $id }}" data-toggle="modal" id="modal-edit" title="Edit"></a>

the modal you want to use

<div class="modal" id="modal-edit-customers{{ $id}}">

...modal content .....

</div>

fullarray's avatar

The short answer is that you must keep your modal within a "@foreach" loop, or you modal will return one record only. One caveat of using modals, it's server workload. You must be aware of the performance implications this will bring if you have 100's or 1000's of records. If you have 5 or 10 records showing in a list on a single page, it won't be troubling. However, if you're showing 100's of records at once. The performance decrement will be noticeable. As an answer to your question, for example(and extending the answer given by @MaverickChan ):

<table>
<thead>
   ...
<thead>
<tbody>
@foreach($yourModel as $SampleModels)

//Your other code implementation goes here
...

<a href="{{route('admin.customers.edit',$id)}}" data-hover="tooltip" data-placement="top" data-target="#modal-edit-customers{{ $id }}" data-toggle="modal" id="modal-edit" title="Edit"></a>

...

//Your other code implementation goes here

...

<div class="modal" id="modal-edit-customers{{ $id}}">

...modal body .....

</div>


@endforeach 
</tbody>
</table>
1 like
PembaSherpa's avatar

How do we update the new information after pulling information?

Please or to participate in this conversation.