从动态行值将数据更新到数据库中

时间:2017-05-18 02:24:56

标签: php laravel laravel-5

我有一个具有动态行值的表,例如:

service_attribute_name               service_attribute_value
------------------------------------------------------------
        Plan                                Antivirus
        Qty                                 1 Bundle
   Subscription_key                         2fsd3rxY

我有查看在foreach循环中显示数据并且可以编辑并且可以保存的视图。保存后,通过表单发送的数据将更新到数据库中。我一直在努力,但无法让它运转起来。以下是刀片和控制器的示例:

刀片:

<select type="text" class="form-control" name="service_status" style=" padding: 3px ;width:40%" >
          <option value="" disabled selected>
              @foreach($data2 as $d2)<?php 
              if($d2->service_status == 'ACTIVE')
                  echo "ACTIVE";
              else
                  echo "PENDING";
                  ?>
              @endforeach
          </option>
          <option value="PENDING">PENDING</option>
          <option value="ACTIVE">ACTIVE</option>

        </select></td><td  ></td>
    </tr>
@foreach($var as $v)
    <tr>
        <td name="attrname"><b>{{ $v->service_attribute_name }}</b><br><br></td>
        <td>: <input contenteditable="true" name="{{ $v->service_attribute_name }}" value="{{ $v->service_attribute_value}}" style="width:300px; border:0;"> <br></td>

    </tr> 
@endforeach

控制器:

foreach ($all_form_fields as $key => $val) {
        if ($key != "_token") {
DB::connection('pgsql_backoffice')->table('tservice_info')
                    ->where('tservice_info.service_attribute_name','=',str_replace("_"," ",$key))
                    ->where('tservice_info.user_id','=',$user_id)
                    ->where('tservice_info.account_no','=',$account_no)
                    ->where('tservice_info.package_id','=',$package_id)
                    ->where('tservice_info.product_id','=',$product_id)
                    ->update(['service_attribute_value'=> $val,'service_status'=>$all_form_fields['service_status'],'actual_activate_date'=>$all_form_fields['actual_activate_date']]);
}
}

0 个答案:

没有答案