我正在创建一个显示一些数据的索引表单。一切都准备好了,但当我删除按钮,我得到一个错误“该方法不支持此路由。支持的方法:GET,HEAD,POST.”
路线
Route::group(['middleware' => ['auth']], function() {
Route::resource('roles','RoleController');
Route::resource('users','UserController');
Route::resource('kamar_theresia','Kamar_TheresiaController');
});
控制器
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
6条答案
按热度按时间yizd12fk1#
确保您的表单没有包含在另一个表单中。我犯了这个愚蠢的错误,得到了同样的错误消息。
z2acfund2#
这是因为你传递了POST方法作为你的表单的方法,这是错误的,正确的做法是传递POST方法。
请看这个例子:
您的控制器应该是:
mdfafbf13#
看起来你快到了!我会使用POST的形式类似于这样:
然后在你的控制器里
剩下的代码应该没问题。如果不行就告诉我。
qv7cva1a4#
在Form中使用
{{ csrf_field() }}
和{{ method_field('DELETE') }}
。在Controller中使用此
如果我们使用的是
Route::resource()
,那么它将通过destroy函数自动路由。hmmo2u0o5#
忘记在开始时使用slash:
在资源控制器中:
cuxqih216#
查看
网站