How to use update Resource Controllers laravel 4?

那年仲夏 提交于 2019-12-07 11:02:25

问题


I have Customer Controller with index, edit, update methods

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

Controller methods update

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

my HTML Form

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

I have following a Documentation here http://four.laravel.com/docs/controllers#resource-controllers PUT/PATCH /resource/{id} update

It's seems not working for me, how to use it? thank you


回答1:


To use the PATH, PUT or DELETE HTML methods you need to add a hidden input with _method. Like the following...

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



回答2:


You can use the Form Builder. Example using blade:

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

That will automatically add this for you

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



回答3:


This works for me in Laravel 4:

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



回答4:


I am using Laravel resource controller. For update a page, I copied it from insert page after then

Just I added an extra field to update view like as

            {{ method_field('put') }}

Just use this as for update

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


来源:https://stackoverflow.com/questions/15214515/how-to-use-update-resource-controllers-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!