MethodNotAllowedHttpException在RouteCollection.php第233行,我认为一切都是正确的
我正在学习laravel,当我调用delete方法时遇到了一个问题 我的路线:MethodNotAllowedHttpException在RouteCollection.php第233行,我认为一切都是正确的,php,laravel,routes,Php,Laravel,Routes,我正在学习laravel,当我调用delete方法时遇到了一个问题 我的路线: Route::get('/', function () { return view('inicio'); }); Route::resource('secciones', 'seccionesController'); {{ Form::open(['route' => ['secciones.destroy', $seccion->id], 'method' => 'DELETE'])
Route::get('/', function () {
return view('inicio');
});
Route::resource('secciones', 'seccionesController');
{{ Form::open(['route' => ['secciones.destroy', $seccion->id], 'method' => 'DELETE']) }}
{{ Form::submit('Delete') }}
{{ Form::close() }}
我的表格:
Route::get('/', function () {
return view('inicio');
});
Route::resource('secciones', 'seccionesController');
{{ Form::open(['route' => ['secciones.destroy', $seccion->id], 'method' => 'DELETE']) }}
{{ Form::submit('Delete') }}
{{ Form::close() }}
$seccion->id是正确的,secciones.destroy(在seccionesController中有一个destroy方法)是正确的。当我呼叫delete laravel时,返回我:
MethodNotAllowedHttpException in RouteCollection.php line 233:
有人能帮我吗
提前感谢。HTML表单不支持删除方法。 但是您可以使用{{method_field('DELETE')}} 另外,您忘了在表单中添加{{csrf_field()}}(令牌字段) 它将是:
{{Form::open(['route'=>['secciones.destroy',$seccion->id],'method'=>'DELETE'])}
{{method_field('DELETE')}
{{csrf_field()}}
{{Form::submit('Delete')}
{Form::close()}
尝试使用路由('secciones.destroy',['id'=>$seccion->id])method=“Delete”
您的代码看起来不错。尝试使用php-artisan-route:clear
清除路由缓存。如果没有帮助,请发布php artisan路由的结果:list
表单::open()
将生成方法字段和CSRF令牌字段,因此您的代码没有任何意义。