无法在laravel';的html模式中获取id;s刀片文件


Unable to get id inside html modal of laravel's blade file

我正在用laravel做项目。我在数据库中有多条记录,这些记录已使用foreach循环显示在laravel的blade文件中。每个记录都有挂起按钮。每当用户单击挂起按钮时,就会打开一个html模式。我想要模态中的记录id,但它总是使用第一个记录id。我的刀片文件看起来像,

 @foreach($providerData as $newprovider)
<h4>Name:{{$newprovider->name}}</h4>
 <button class="btn btn-default" data-toggle="modal" data-target="#Pendingnote">Pending</button>
{!! Form::model( $newprovider->id ,['method' => 'PATCH','action'=>['superadminController@pendingProvider', $newprovider->id]]) !!}
<div class="modal fade" id="Pendingnote" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Note {!! $newprovider->id !!}</h4>
            </div>
            <div class="modal-body">
                <input type="text" class="form-control" name="note" value="{{ old('note') }}">
            </div>
            <div class="modal-footer">
                {!! Form::submit('Add', ['class' => 'btn btn-default']) !!}
            </div>
        </div>
    </div>
    <input type="hidden" name="_token" value="{{ csrf_token() }}">
</div>    
{!! Form::close() !!}
@endforeach

无论点击哪条记录,它都会返回$newprovider->id作为第一条记录的id。我不知道哪里出错了。请提前提供帮助并表示感谢。

做这些事情是为了让模式发挥作用。

编辑按钮以:

<button class="btn btn-default" data-toggle="modal" data-target="#Pendingnote{{$newprovider->id}}">Pending</button>

和模式容器到:

<div class="modal fade" id="Pendingnote{{$newprovider->id}}" role="dialog">

所有模式触发按钮都有data-target="#Pendingnote",这意味着它们都会触发具有所能找到的id的第一个模式。

例如,您可以尝试删除data-target属性,并使用一点jQuery触发模态,如:

$('button[data-toggle]').on('click', function () {
  $(this).next('form').find('.modal').modal('show');
});

无论如何,我建议在模态中使用form。所以jQuery应该是:

$('button[data-toggle]').on('click', function () {
  $(this).next('.modal').modal('show');
});

最后,看看这个:http://getbootstrap.com/javascript/#modals-相关目标