【发布时间】:2020-02-27 18:40:47
【问题描述】:
我有这个错误:
缺少 [Route: admin.destroy] [URI: admin/{admin}] 的必需参数
这是所有的视图,所有的变量, 我尝试了很多,但我不知道如果我改变第二个参数 $info 有什么问题 出现此错误 此路由不支持 DELETE 方法。支持的方法:GET、HEAD、POST。
<div class="table-responsive">
<table class=" table ">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Code</th>
<th scope="col">Phone</th>
<th scope="col">Phone 2</th>
<th scope="col">Delete</th>
{{-- <th scope="col">email</th> --}}
</tr>
</thead>
<tbody>
@foreach ($infos as $info)
<tr>
<td>{{ $info->id }}</td>
<td>{{ $info->name}}</td>
<td>{{ $info->code }}</td>
<td>{{ $info->phone }}</td>
<td>{{ $info->phone2 }}</td>
<td>
<button class="btn btn-danger btn-sm" onclick="handleDelete ({{ $info->id }})">Delete
</button>
</td>
{{-- <td>{{ $info->email }}</td> --}}
</tr>
@endforeach
</tbody>
</table>
</div>
<form action="{{ route('admin.destroy',['admin' => $info])}}" method="post" id="deleteInfoForm">
@method('DELETE')
@csrf
<div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="deleteModal"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="deleteModal">Delete Info</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p class=" text-center text-bold">Are your sure ?</p>
</div>
<div class="modal-footer ">
<button type="button" class="btn btn-secondary" data-dismiss="modal">No , Go back</button>
<button type="submit" class="btn btn-danger">Yes , Delete</button>
</div>
</div>
</div>
</div>
</form>
这是我从 AdminController 中删除的功能
public function destroy(Info $admin)
{
// $info = Info::find($id);
$admin->delete();
// session()->flash('succuss', 'Info deleted successfully');
return redirect('/admin');
}
我的路由列表
| DELETE | admin/{admin} | admin.destroy | App\Http\Controllers\AdminController@destroy
【问题讨论】: