2013-03-05 77 views
4

我有客户控制器,带指数,编辑,更新方法如何使用更新资源控制器laravel 4?

Route::resource('customer', 'CustomerController'); 

控制器方法更新

public function update($id) { echo $id; } 

我的HTML表单

<form action="/customer/1" method="post"> 
<input type="text" name="email" value="" /> 
<input type="submit" value="" /> 
</form> 

我有如下一个文档在这里 http://four.laravel.com/docs/controllers#resource-controllers PUT/PATCH/resource/{id}更新

这似乎不适合我,如何使用它?谢谢

回答

14

要使用你需要添加一个隐藏的输入与_methodPATHPUTDELETE HTML方法。如下所示...

<input type="hidden" name="_method" value="PUT" /> 
+0

它的工作,万分感谢。 :d – Joanhard 2013-03-05 02:12:13

6

您可以使用Form Builder。例如,使用刀片:

{{ Form::open(array('method' => 'DELETE')) }} 

,将自动添加此为您

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

这对我的作品在Laravel 4:

{{ Form::open(array('url' => URL::to('customer/1'), 'method' => 'PUT')) }} 
0

我使用Laravel资源控制器。对于更新网页,我复制它插入页再经过

只是我增加了一个额外的字段更新视图等作为

  {{ method_field('put') }} 

就以此作为更新

<form method="post" action="{{ URL::to('customer',$customer['id'])}}"> 
      {{ csrf_field() }} 
      {{ method_field('put') }} 
相关问题