【问题标题】:Laravel data not going appropriately into the databaseLaravel 数据未正确进入数据库
【发布时间】:2017-06-27 09:39:35
【问题描述】:

我需要的是,如果我获得MOB/TR/1743 的第一个元素ID,然后按下与id 相关的标记按钮数据必须进入数据库。

这是数据库中应该有的内容。

但这就是我要进入数据库的内容。这意味着将另一列数据导入数据库。

这是那个观点。

<div class="row">
   <section id="feature" class="section-padding wow fadeIn delay-05s">
      <div class="container">
        <div class="row">
          <div class="col-md-12 col-sm-6 col-xs-12">
            <div class="wrap-item text-center">

              <div class="jumbotron">
                  <div class="item-img">
                     <img src="images/ser02.png">
                  </div>

                  <div class="form-group">                    
                      <form action="search" method="post" class="form-inline">    
                            <select name="institute" id="institute">
                                <option selected="selected" value="id">Trainee Id</option>
                                <option value="full_name">Trainee Name</option>
                                <label for="Search">Name</label>
                            </select>
                            <input type="text" name="search" /><br>
                            <input type="hidden" value="{{ csrf_token() }}" name="_token" />
                            <input type="submit" name="submit" value="Search">
                      </form>
                  </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>
</div>

<div class="col-md-12 col-sm-6 col-xs-12">
   <div class="panel panel-default">
      <div class="panel-body">
          <table class="table table-striped">
                <thead>    
                   <th>Trainee ID</th>
                   <th>Name with Initials</th> 
                   <th>Time</th>
                   <th>Mark Here!</th>
                 </thead>
                 <tbody>
                 <form action="{{route('TraineeAttendance.store')}}" method="post" >
                  {{ csrf_field() }}  
                  @foreach($items as $item)
                  <tr>
                    <td>
                       <div class="form-group">
                          <input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
                       </div>
                    </td>
                     <td>
                          <div class="form-group">
                              <input type="text" name="name" class="form-control" value="{{ $item->name_with_initials }}">
                          </div>
                     </td>
                     <td>
                         <label><input type="checkbox" name="time" id="time" value="time">&nbsp; Time</label>
                     </td>
                     <td>
                          <input type="submit" class="btn btn-info">  
                     </td>
                  </tr>
                  @endforeach
                </form>    
                </tbody>
          </table>
      </div>
   </div>
</div>

为什么我得到错误的数据?

【问题讨论】:

  • 如果您有多个输入具有相同的name 属性值,则只会提交最后一个。

标签: php database laravel laravel-5 view


【解决方案1】:

试试这个希望对你有帮助

                    @foreach($items as $item)

          <form action="{{route('TraineeAttendance.store')}}" method="post" >
           {{ csrf_field() }}  
              <tr>
                 <td>
                    <div class="form-group">
                    <input type="text" name="trainee_id" class="form-control" value="{{ $item->trainee_id }}">
                    </div>
                 </td>

                  <td>
                  <div class="form-group">
                    <input type="text" name="name" class="form-control" value="{{ $item->name_with_initials }}">
                    </div>
                  </td>

                  <td>
                    <label><input type="checkbox" name="time" id="time" value="time">&nbsp; Time</label>
                  </td>

                    <td>
                    <input type="submit" class="btn btn-info">

                  </td>
              </tr>
                    </form>    
                    @endforeach

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-27
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多