laravel - laravel 删除表单不起作用
问题描述
@extends('layouts.app')
@section('content')
<div class="row">
<div style="float:left;" class="col-md-8">
<h3>Currency</h3>
</div>
<div style="float:right;" class="col-md-4">
<a href="/currency/create" class="btn btn-dark btn-sm ml-3" style="float: right"><i class="fa fa-edit" style="color:white;"></i>Add New</a>
<input type="text" id="search" name="search" placeholder="search" class="form-control-sm col-md-8 ml-1" style="float:right;"><br><br>
</div>
</div>
@if(count($currencies) > 0 )
<table class="table table-striped table-sm" >
<thead>
<tr><th scope="col">ID</th><th scope="col">Currency</th><th scope="col">Country</th><th scope="col" colspan="2" style="text-align:right">Actions</th></tr>
</thead>
@foreach($currencies as $currency)
<tr><td scope="row">{{$currency->id}}</td>
<td>{{$currency->title}}</td>
<td>{{$currency->country}}</td>
{!!Form::open(['action'=>['CurrencyController@destroy', $currency->id], 'method'=>'POST'])!!}
{{Form::hidden('_method','DELETE')}}
@csrf
<td><button type="submit" class="btn btn-danger btn-sm" style="float:right"><i class="fa fa-remove" style="color:white;"></i>Delete</button>
<a href="/currency/{{$currency->id}}/edit" class="btn btn-primary btn-sm" style="float:right" ><i class="fa fa-edit" style="color:white;"></i>Edit</a></td></tr>
{!!Form::close() !!}
@endforeach
</table>
{{$currencies->links()}}
@else
<p> No Data Available </p>
@endif
@endsection
大家好, 删除表单未在此代码中提交,我尝试了很多东西,但我无法弄清楚问题所在。请帮我解决一下这个。
解决方案
在我看来,您的 html 是错误的,您打开、关闭表单并放置@csrf
在td
标签之外,而提交按钮在其中
尝试将您的表单定义移动到td
标签内,例如:
<td>
{!!Form::open(['action'=>['CurrencyController@destroy', $currency->id], 'method'=>'POST'])!!}
{{Form::hidden('_method','DELETE')}}
@csrf
<button type="submit" class="btn btn-danger btn-sm" style="float:right"><i class="fa fa-remove" style="color:white;"></i>Delete</button>
<a href="/currency/{{$currency->id}}/edit" class="btn btn-primary btn-sm" style="float:right" ><i class="fa fa-edit" style="color:white;"></i>Edit</a>
{!!Form::close() !!}
</td>
推荐阅读
- php - 带有 PHP 框架的 Subdir 的 NGINX 问题
- algorithm - 链表的时间复杂度是多少
- ruby - Ruby 将十六进制转换为整数(带符号的 16 位)
- python - Flake8 - 指定要忽略的错误范围?
- angular - Angular2:每个延迟加载的子模块中的自定义材质主题
- mysql - sql:列索引 19 上的扫描错误,名称“L2Name”:不支持扫描,存储驱动程序。值类型
输入 *string - arrays - 如何将 for 循环中的数据存储到数组中?
- html - Angular 2+:输入装饰器不反映复选框
- datetime - Dart/Flutter 如何比较两个 TimeOfDay 时间?
- javascript - parseFloat 在动画中加倍操作数