【问题标题】:How to update multiple datas submitted from html form to the respective ids in the database in laravel?如何将html表单提交的多个数据更新到laravel数据库中的各个id?
【发布时间】:2021-08-31 06:29:10
【问题描述】:

我从数据库中检索表。每行都有自己的操作列,其中有单选按钮,如 po、ao、rac、rap、cancel、hold 和通过隐藏字段提供的 ID。如何循环遍历所有数据和所有相应的 id 以在数据库中更新。我的数据库表名称是文档,其中单选按钮值应在数据库的 payment_comment 字段中提交更新:我不明白如何遍历所有相应的 id 并更新数据库。

这是我的看法:

<form action="payment_prepared" method="POST">
@csrf
  <input type="submit" name="submit">

      <div class="table-responsive">

        <table class="table custom-table">
          <thead>
            <tr>
              <th scope="col">
                <label class="control control--checkbox">
                  <input type="checkbox" class="js-check-all"/>
                  <div class="control__indicator"></div>
                </label>
              </th>
              <th scope="col" >S.N</th>
              <th scope="col">LC NO</th>
              <th scope="col">Applicant</th>
              <th scope="col">Doc Value</th>
              <th scope="col">Doc Received date</th>
              <th scope="col">LC Type</th>
              <th scope="col">Action</th>
            </tr>
          </thead>
          <tbody>
            <?php $number = 1;?>
            @foreach($datas as $items)
              
            <tr>
              <th scope="row" style="padding:20px">
                <label class="control control--checkbox">
                  <input type="checkbox"/>
                  <div class="control__indicator"></div>
                </label>
              </th>
              <td>{{$number}}</td>
              <td>{{$items->lc_no}}</td>
              <td>{{$items->applicant}}</td>
              <td>{{$items->doc_value}}</td>
              <td>{{$items->rec_date}}</td>
              <td>{{$items->sight_usance}}</td>
              
     <input type="hidden" name="id" value="{{$items->id}}">
    <td>
    <label class="radio-inline"><input type="radio" name="pmt_msg" value="PO"> PO
    </label>
    <label class="radio-inline"><input type="radio" name="pmt_msg" value="AO"> AO
    </label>
    <label class="radio-inline"><input type="radio" name="pmt_msg" value="Rac"> RA/C
    </label>
    <label class="radio-inline"><input type="radio" name="pmt_msg" value="rap"> RA/P
    </label>
    <label class="radio-inline"><input type="radio" name="pmt_msg" value="cancel"> Cancel
    </label>
    <label class="radio-inline"><input type="radio" name="pmt_msg" value="hold"> Hold
    </label>

  </td>



            </tr>
            <?php $number++; ?>
            @endforeach
         
            
          </tbody>
        </table>
      </div>

      </form>

我的控制器

function payment_prepared(Request $req){

            $data = $req->all();
                foreach($data as $ids){}

【问题讨论】:

    标签: laravel laravel-8


    【解决方案1】:

    只需像这样为您的名字添加前缀:

     <label class="radio-inline"><input type="radio" name="items[{{ $item->id}}][pmt_msg][]" value="PO"> PO
        </label>
    

    然后在你的控制器中:

    foreach($req->items as $item){
        //$item[pmt_msg]...
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 2019-03-19
      相关资源
      最近更新 更多