Laravel 5删除RouteCollection.php第207行中的MethodNotAllowedHttpException:

时间:2015-08-06 17:02:09

标签: laravel-5 laravel-routing

我正在使用Laravel 5 - 我在一个网站上工作但在另一个网站上工作我不断收到错误:

MethodNotAllowedHttpException in RouteCollection.php line 207:

我尝试过使用js删除处理程序并尝试过此表单:

<form action="/order/12" method="POST"> 
   <input type="_method" name="action" value="delete">
   <input type="text" name="_token" value="<?php echo csrf_token(); ?>">
   <input type="submit">
</form>

| | GET|HEAD | order | order.index | App\Http\Controllers\OrderController@index | auth | | | GET|HEAD | order/create | order.create | App\Http\Controllers\OrderController@create | auth | | | POST | order | order.store | App\Http\Controllers\OrderController@store | auth | | | GET|HEAD | order/{order} | order.show | App\Http\Controllers\OrderController@show | auth | | | GET|HEAD | order/{order}/edit | order.edit | App\Http\Controllers\OrderController@edit | auth | | | PUT | order/{order} | order.update | App\Http\Controllers\OrderController@update | auth | | | PATCH | order/{order} | | App\Http\Controllers\OrderController@update | auth | | | DELETE | order/{order} | order.destroy | App\Http\Controllers\OrderController@destroy | auth |

2 个答案:

答案 0 :(得分:3)

您没有正确命名输入,

变化

<input type="_method" name="action" value="delete">

<input type="hidden" name="_method" value="DELETE">

答案 1 :(得分:0)

它是创建删除表单的一些辅助函数:)

function delete_form($routeParams , $label = 'Delete'){
  $form = Form::open(['route' => $routeParams, 'method' => 'DELETE']);
  $form .= Form::submit($label , ['class' => 'btn btn-danger btn-xs']);
  return $form .= Form::close();
}