【问题标题】:How to use update Resource Controllers laravel 4?如何使用更新资源控制器 laravel 4?
【发布时间】:2013-02-19 07:20:34
【问题描述】:

我有带有索引、编辑、更新方法的客户控制器

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


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      您可以使用Form Builder。使用刀片的示例:

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

      它会自动为你添加这个

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

      【讨论】:

        【解决方案3】:

        这在 Laravel 4 中适用于我:

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

        【讨论】:

          【解决方案4】:

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

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

                      {{ method_field('put') }}
          

          只用这个作为更新

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

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2013-07-30
            • 1970-01-01
            • 2013-08-20
            • 1970-01-01
            • 1970-01-01
            • 2014-02-18
            • 2014-10-22
            相关资源
            最近更新 更多