如何使用更新资源控制器laravel 4?

问题描述 投票:4回答: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}更新

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

php laravel routes laravel-4 controllers
4个回答
15
投票

要使用PATHPUTDELETE HTML方法,您需要使用_method添加隐藏输入。如下......

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

7
投票

你可以使用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资源控制器。为了更新页面,我在那之后从插入页面复制了它

只是我添加了一个额外的字段来更新视图,如as

            {{ method_field('put') }}

只需使用它作为更新

 <form method="post" action="{{ URL::to('customer',$customer['id'])}}">
            {{ csrf_field() }}
            {{ method_field('put') }}
© www.soinside.com 2019 - 2024. All rights reserved.