Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MethodNotAllowedHttpException在RouteCollection.php第233行,我认为一切都是正确的_Php_Laravel_Routes - Fatal编程技术网

MethodNotAllowedHttpException在RouteCollection.php第233行,我认为一切都是正确的

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'])

我正在学习laravel,当我调用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令牌字段,因此您的代码没有任何意义。