我有用户表,每行包含一个删除用户行的按钮。 按钮上的clic显示删除确认的模式。 但尝试删除行时仍然有此错误。 MethodNotAllowedHttpException
这是模态代码:
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
Log.e("sara" , "this part takes time");
LayoutInflater inflater = getLayoutInflater();
convertView = getLayoutInflater().inflate(R.layout.gallery_gridsq, parent, false);
iv = (ImageView) convertView.findViewById(R.id.icon);
file = new File(Uri.parse(getItem(position).toString()).getPath());
Uri imageUri = Uri.fromFile(file);
Glide
.with(Gallery2.this)
.load(imageUri)
.into(iv);
return convertView;
}
我的jquery代码:
<div class="modal fade " id="modal-delete">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body">
<p>Voulez-vous supprimer cet utilisateur ?</p>
</div>
<div class="modal-footer">
<!------------------------
<a href='/SurveyApp/public/admin/{{ $user->id }}/delete' class="btn btn-primary" data-dismiss="modal" class=" modal-action waves-effect waves-light btn-flat red-text">oui</a>
---------------->
<form method="POST" action="/SurveyApp/public/admin/{{ $user->id }}/delete" id="delete-court-form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="DELETE">
<button type="button" class="btn btn-default"
data-dismiss="modal">Fermer</button>
<!-- <a href='/SurveyApp/public/admin/{{ $user->id }}/delete' class="btn btn-danger">oui!</a> -->
<button type="submit" class="btn btn-danger" id="delete-court-button" >
<i class="fa fa-times-circle"></i> Oui
</button>
</form>
和控制器中的方法:
<script>
$('.delete-court-button').on('click', function () {
$('#delete-court-form').attr('action', $(this).data('delete-link'));
});
</script>
答案 0 :(得分:0)
route()
帮助程序创建删除链接所以你的表格应该是这样的:
<form method="POST" action="{{route('delete.user',$user->id)}}" id="delete-court-form">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="DELETE">
<button type="button" class="btn btn-default"
data-dismiss="modal">Fermer
</button>
<button type="submit" class="btn btn-danger" id="delete-court-button">
<i class="fa fa-times-circle"></i> Oui
</button>
</form>
您的路线定义:
Route::delete('/admin/{user}/delete','AdminController@delete')->name('delete.user')->middleware('is_admin');
你的控制器方法:
public function delete($user_id){
$user = User::findOrFail($user_id);
$surveys=Survey::where('user_id',$user->id)->get();
$user->delete();
foreach($surveys as $survey){
$survey->delete();
}
return redirect('/admin/user');
}
答案 1 :(得分:0)
检查你的路线
示例: 路线:柱( '/管理/ {用户} /删除', 'AdminController @删除')
表单和路由方法都应该有相同的方法(“POST”)