du127953 2016-05-31 19:39
浏览 67

使用数组laravel 5.2进行更新

I need to update my data table.

From my input name, need all the fields with to be updated with the value of the latter coming from ask_id form:

{!! Form::open(array('url'=>array('/formato/'.$formato->id.'/update'), 'method'=>'PATCH')) !!}
        <div class="row">
            @foreach($pregunta as $preguntas)
            <div class="col-md-4">
                <div class="form-group">
                    {!! Form::hidden('ask_id[]', $preguntas->id) !!}
                    {!! Form::text('name[]', $preguntas->name, ['class'=>'form-control']) !!}
                </div>
            </div>
            @endforeach
        </div>
        <div class="row">
            <div class="col-md-4">
                <button class="btn btn-block btn-success">
                    Actualizar
                </button>
            </div>
        </div>
    {!! Form::close() !!}

Controller:

public function formatoUpdate(Request $request, $id)
    {

        $item = $request->input('name');
        $ask = $request->input('ask_id');

        foreach ($ask as $ask_id)
        {
            $pregunta = ask::find($ask_id);
            $pregunta->update($item);
        }

        return redirect('/formato');
    }
  • 写回答

2条回答 默认 最新

  • doutan1875 2016-05-31 22:39
    关注

    I am not sure what pregunta is but you could try:

    $pregunta->name = $item; //name is the field in your table
    $pregunta->save();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探