Problem with print user id in bootstrap modals in foreach

i have problem with printing user id in bootstrap modal in php foreach (laravel framework)
i have below code:

@foreach($users as $user)
                        <td> {!! $user->name !!}</td>
                        <td> {!! $user->email !!}</td>

                            <a class="btn btn-app" href="#" data-toggle="modal" data-target="#modal-danger">
                                <i class="fa  fa-trash"></i>delete

                            <div class="modal modal-danger fade" id="modal-danger">
                                <div class="modal-dialog">
                                    <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">delete</h4>
                                        <div class="modal-body">
                                            <p>are you sure wana delete this user?</p>
                                        <div class="modal-footer">
                                            <button type="button" class="btn btn-outline pull-left" data-dismiss="modal">no</button>
                                           {{-- <a class="btn btn-outline" href="{{action('UserController@delete',[$user->id]) }}" >
yes                                            </a>--}}
                                    <!-- /.modal-content -->
                                <!-- /.modal-dialog -->



first i want to print all users information in table. and want delete user with html link. so i need his/her id, but when i print table just latest user id is printed in modal…every thing is fine in foreach but in modal just latest user id will print and for every user i press delete button just latest user will delete.
i think bootstrap modal just print once and every time in foreach this modal replacing,

do you know how can i solve this problem?

Hi everybody.

You are adding modal windows inside the @ foreach cycle. It should be located outside of the @ foreach.


thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.