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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15214515/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 07:35:40  来源:igfitidea点击:

How to use update Resource Controllers laravel 4?

phplaravelrouteslaravel-4controllers

提问by Joanhard

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

我的 HTML 表单

<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-controllersPUT/PATCH /resource/{id} update

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

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

它似乎对我不起作用,如何使用它?谢谢你

回答by Robbo

To use the PATH, PUTor DELETEHTML methods you need to add a hidden input with _method. Like the following...

要使用PATH,PUTDELETEHTML 方法,您需要使用_method. 像下面这样...

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

回答by mul14

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">

回答by Melvin

This works for me in Laravel 4:

这在 Laravel 4 中对我有用:

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

回答by Kabir Hossain

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

我正在使用 Laravel 资源控制器。为了更新页面,我之后从插入页面复制了它

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') }}