dsjojts9734 2019-01-29 00:29
浏览 90
已采纳

数据仅在Laravel应用程序中插入最后一个数组

I have a list of days for this month. But the problem is when I insert or add the data it only entered the last array or data from the list. For example, I add Jan-02-2019, and it will then insert Jan-31-2019.

Controller

public function insertSchedule(Request $request)
{
    $employeeTimeSet = new Schedule;
    $employeeTimeSet->employee_no = $request->input('hidEmployeeno');
    $employeeTimeSet->last_name = $request->input('hidEmployeeLast');
    $employeeTimeSet->first_name = $request->input('hidEmployeeFirst');
    $employeeTimeSet->date_today = $request->input('dateToday');
    $employeeTimeSet->time_in = $request->input('timeIn');
    $employeeTimeSet->time_out = $request->input('timeOut');
    $employeeTimeSet->save();
}

Here are the view and form:

{!! Form::open(['action' => 'Admin\EmployeeFilemController@insertSchedule', 'method' => 'POST']) !!}
<div class="row">
    <div class="form-group col-md-12">
        <small>Employee No. and Name:</small>
        <b><i> {{ $employee->employee_no }} : {{ $employee->last_name }}, {{ $employee->first_name }}</i></b>
        <input type="hidden" name="hidEmployeeno" value='<?php echo $employee->employee_no ?>'>
        <input type="hidden" name="hidEmployeeLast" value='<?php echo $employee->last_name ?>'>
        <input type="hidden" name="hidEmployeeFirst" value='<?php echo $employee->first_name ?>'>
        <hr>
    </div>
</div>
@php
    $today = today(); 
    $dates = []; 

    for($i=1; $i < $today->daysInMonth + 1; ++$i) {
        $dates[] = \Carbon\Carbon::createFromDate($today->year, $today->month, $i)->format('F-d-Y');
    }
@endphp

<table class="table">
    <thead>
    <tr>
        <th>DATE TODAY</th>
        <th>TIME IN</th>
        <th>TIME OUT</th>
        <th>ACTION</th>
    </tr>
    </thead>
    <tbody>
    @foreach($dates as $date)
        <tr>
            <td><b>{{ $date }}</b></td>
            <input type="hidden" name="dateToday" value="{{ $date }}">
            <td><input type="time" name="timeIn" class="form-control col-md-10"></td>
            <td><input type="time" name="timeOut" class="form-control col-md-10"></td>
            <td>{{Form::button('<i class="fa fa-clock">&nbsp;&nbsp;SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm',  'style'=>"display: inline-block;"])}}</td>
        </tr>
    @endforeach
    </tbody>
</table>
{!! Form::close() !!}
  • 写回答

1条回答 默认 最新

  • duanshaiduhao2471 2019-01-29 05:56
    关注

    I think it's because of the way you structured your HTML form. If I understood your question correctly, the following should make it work:

    @php
        $today = today(); 
        $dates = []; 
        for($i=1; $i < $today->daysInMonth + 1; ++$i) {
            $dates[] = \Carbon\Carbon::createFromDate($today->year, $today->month, $i)->format('F-d-Y');
        }
    @endphp
    <div class="row">
        <div class="form-group col-md-12">
            <small>Employee No. and Name:</small>
            <b><i> {{ $employee->employee_no }} : {{ $employee->last_name }}, {{ $employee->first_name }}</i></b>
            <hr>
        </div>
    </div>
    <table class="table">
        <thead>
        <tr>
            <th>DATE TODAY</th>
            <th>TIME IN</th>
            <th>TIME OUT</th>
            <th>ACTION</th>
        </tr>
        </thead>
        <tbody>
        @foreach($dates as $date)
            {!! Form::open(['action' => 'Admin\EmployeeFilemController@insertSchedule', 'method' => 'POST']) !!}
                <input type="hidden" name="hidEmployeeno" value="{{ $employee->employee_no }}">
                <input type="hidden" name="hidEmployeeLast" value="{{ $employee->last_name }}">
                <input type="hidden" name="hidEmployeeFirst" value="{{ $employee->first_name }}">
                <tr>
                    <td><b>{{ $date }}</b></td>
                    <input type="hidden" name="dateToday" value="{{ $date }}">
                    <td><input type="time" name="timeIn" class="form-control col-md-10"></td>
                    <td><input type="time" name="timeOut" class="form-control col-md-10"></td>
                    <td>{{ Form::button('<i class="fa fa-clock">&nbsp;&nbsp;SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm',  'style'=>"display: inline-block;"]) }}</td>
                </tr>
            {!! Form::close() !!}
        @endforeach
        </tbody>
    </table>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效