当我显示集合中的所有内容时,我有一个脚本,我使用foreach。你可以删除点击特定按钮的所有集合中的一个,但问题是你可以点击ID为17的集合,它将删除第一个现有的集合,即使id = 1.我不知道该怎么办,因为我认为一切看起来都不错。当我转储控制器时,我看到第一个现有的集合ID。我的意思是那个时刻 - > ReviewAnswerController @ destroy in code
你能帮助我吗?
@foreach($data->reviewAnswers as $answer)
<div class="row">
<div class="col-md-12" style="position: inherit; display: flow-root; float: right; background: #94969f; margin-top: 15px; margin-right: 15px; padding: 5px; border-radius: 5px; width: 80%; color: white; padding-bottom: 3px;">
<div class="col-md-1">
<?php $avAnswer = App\Models\UserData::where('user_id', $data->sender_id)->first() ?>
@if(empty($avAnswer->avatar))
<img src="{{ asset('img/lock_thumb.jpg')}}" style="width: 50px; height: 50px; border: 2px solid white;border-radius: 50%;">
@else
<img src="{{ asset('/storage/uploads/avatars/'. $av->avatar) }}" style="width: 50px; height: 50px; border: 2px solid white;border-radius: 50%;">
@endif
</div>
<div class="col-md-5">
<div style="float: left;">
{{$answer->id}}
<b>{{$answer->sender_name}} {{$answer->sender_surname}}</b> |
@if($answer->sender_role_specific)
{{$answer->sender_club_role}} ({{$answer->sender_role_specific}})
@else
{{$answer->sender_club_role}}
@endif
</div>
</div>
<div class="col-md-5"></div>
<div class="col-md-1">
@if(Auth::user()->role == 'admin')
<form id="reviewAnswerForm" action="{{ action('ReviewAnswerController@destroy', $answer->id) }}" method="POST">
{{ method_field('DELETE') }} {{ csrf_field() }}
<button class="btn" style="background-color:transparent; float: right;">
<img src="{{ asset('img/review-icons/delete.png')}}" style="float: right;"/>
</button>
</form>
@endif
</div>
<div class="col-md-11" style="border-top: 1px solid; padding-bottom: 5px;">
<p>{{$answer->answer}}</p>
<button class="btn" style="background-color:transparent; float: right;" data-toggle="modal" data-target="#modalreportanswer">
<img src="{{ asset('img/review-icons/report.png')}}" style="width: 15px; height: 15px; float: right; margin-top: 10px;">
</button>
<div class="modal fade" id="modalreportanswer" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">@lang('main.report')</h4>
</div>
<div class="modal-body">
<form action="{{ action('ReviewAnswerReportController@store') }}" method="POST" class="">
{{ csrf_field() }}
<div class="form-group">
<label for="comment">@lang('main.reason'):</label>
<textarea id="text" class="form-control noresize" rows="5" name="reason"></textarea>
<h6 class="pull-right" id="count_message"></h6>
</div>
<div class="form-group">
<input type="hidden" class="form-control" value="{{ $answer->id }}" name="reviewAnswerId">
</div>
<button class="btn btn-primary" type="submit">@lang('main.report')!</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
@endforeach
答案 0 :(得分:1)
在您的代码中,您有2个方法,POST和DELETE在同一个表单
<form id="reviewAnswerForm" action="{{ action('ReviewAnswerController@destroy', $answer->id) }}" method="POST">
{{ method_field('DELETE') }} {{ csrf_field() }}
试试这个,我使用Laravel Collective,非常清楚。
Route::delete('answer/{id}', ['as' => 'reviewAnswer.destroy', 'uses' => 'ReviewAnswerController@destroy'] );
@if(Auth::user()->role == 'admin')
{!! Form::open(['method' => 'DELETE','route' => ['reviewAnswer.destroy',
$answer->id, ] ]) !!}
@endif