2013-03-05 128 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') }} 
相關問題