我正在创建一个显示一些数据的索引表单。一切准备就绪,但当我点击删除按钮时,出现错误“此路由不支持 DELETE 方法。支持的方法:GET、HEAD、POST。”
路线
Route::group(['middleware' => ['auth']], function() {
Route::resource('roles','RoleController');
Route::resource('users','UserController');
Route::resource('kamar_theresia','Kamar_TheresiaController');
});
Controller
public function destroy($id)
{
Kamar_Theresia::find($id)->delete();
return redirect()->route('kamar_theresia.index')
->with('success','Kamar Theresia deleted successfully');
}
查看
@foreach ($kamar_theresia as $tere)
<tr>
<td>{{ ++$i }}</td>
<td>{{ $tere->nama }}</td>
<td>{{ $tere->name }}</td>
<td>{{ $tere->ketersediaan }}</td>
<td>
@can('theresia-delete')
{!! Form::open(['method' => 'DELETE','route' => ['kamar_theresia.destroy', $tere->id],'style'=>'display:inline']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
@endcan
</td>
</tr>
@endforeach
最佳答案
那是因为您将 DELETE 方法作为表单的方法传递,这是错误的,正确的做法是传递 de POST 方法。
检查这个例子:
<form action="{{ route('kamar_theresia.destroy', $tere->id) }}" method="POST">
@csrf
@method('delete')
<button type="submit" class="btn btn-outline-danger">Delete</button>
</form>
你的 Controller 应该是:
public function destroy(Kamar_Theresia $khamar_teresia)
{
$khamar_teresia->delete();
return redirect()->route('kamar_theresia.index')
->with('success','Kamar Theresia deleted successfully');
}
关于laravel - 此路由不支持 DELETE 方法。支持的方法 : GET, HEAD, POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56293326/