我有这个月的天数列表.但问题是当我插入或添加数据时,它只输入了列表中的最后一个数组或数据.例如,我添加 Jan-02-2019,
然后它会插入 Jan-31-2019
.
控制器
公共函数insertSchedule(Request $request){$employeeTimeSet = 新时间表;$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();}
这是视图和表单:
{!!Form::open(['action' => 'AdminEmployeeFilemController@insertSchedule', 'method' => 'POST']) !!}<div class="row"><div class="form-group col-md-12"><small>员工编号和姓名:</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 ?>'><小时>
@php$今天=今天();$dates = [];for($i=1; $i <$today->daysInMonth + 1; ++$i) {$dates[] = CarbonCarbon::createFromDate($today->year, $today->month, $i)->format('F-d-Y');}@endphp<table class="table"><头><tr><今天>今天</th><th>TIME IN</th><th>超时</th><th>Action</th></tr></thead>
@foreach($dates 作为 $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"> SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm', 'style'=>"display: inline-block;"])}}</td></tr>@endforeach</tbody>{!!表单::关闭() !!}我认为这是因为您构建 HTML 表单的方式.如果我正确理解了您的问题,以下内容应该可以解决问题:
@php$今天=今天();$dates = [];for($i=1; $i <$today->daysInMonth + 1; ++$i) {$dates[] = CarbonCarbon::createFromDate($today->year, $today->month, $i)->format('F-d-Y');}@endphp<div class="row"><div class="form-group col-md-12"><small>员工编号和姓名:</small><b><i>{{ $employee->employee_no }} : {{ $employee->last_name }}, {{ $employee->first_name }}</i></b><小时><table class="table"><头><tr><今天>今天</th><th>TIME IN</th><th>超时</th><th>Action</th></tr></thead>
@foreach($dates 作为 $date){!!Form::open(['action' => 'AdminEmployeeFilemController@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"> SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm', 'style'=>"display: inline-block;"]) }}</td></tr>{!!表单::关闭() !!}@endforeach</tbody>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' => 'AdminEmployeeFilemController@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[] = CarbonCarbon::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"> SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm', 'style'=>"display: inline-block;"])}}</td>
</tr>
@endforeach
</tbody>
</table>
{!! Form::close() !!}
解决方案 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[] = CarbonCarbon::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' => 'AdminEmployeeFilemController@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"> SET TIME</i>',['type' => 'submit','class' => 'btn btn-warning btn-sm', 'style'=>"display: inline-block;"]) }}</td>
</tr>
{!! Form::close() !!}
@endforeach
</tbody>
</table>
这篇关于数据仅在 Laravel 应用程序中插入最后一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
相关文章
- MySQLi准备好的语句&foreach 循环MySQLi prepared statement amp; foreach loop(MySQLi准备好的语句amp;foreach 循环)
- mysqli_insert_id() 是从整个服务器还是从同一用户获Is mysqli_insert_id() gets record from whole server or from same user?(mysqli_insert_id() 是从整个服务器还是从同一用户获取记录?)
- PHP MySQLi 无法识别登录信息PHP MySQLi doesn#39;t recognize login info(PHP MySQLi 无法识别登录信息)
- mysqli_select_db() 需要 2 个参数mysqli_select_db() expects exactly 2 parameters(mysqli_select_db() 需要 2 个参数)
- Php mysql pdo 查询:用查询结果填充变量Php mysql pdo query: fill up variable with query result(Php mysql pdo 查询:用查询结果填充变量)
- MySQLI 28000/1045 用户“root"@“localhost"的访问MySQLI 28000/1045 Access denied for user #39;root#39;@#39;localhost#39;(MySQLI 28000/1045 用户“root@“localhost的访问被拒绝)
最新文章
- 如何在 Laravel eloquent 中进行子查询?
- Laravel 高级搜索查询修复
- 雄辩的 laravel WhereIn All
- Laravel 'like' 查询与 MongoDB 连接
- Laravel - 数据透视表上的附加关系
- 更新 Laravel 5.3 中的一对多关系
- Laravel 4 eloquent 模型链接额外的 where 子句
- Laravel - 方法 Illuminate\Support\Collection::makeHidden 不
- Laravel whereIn whereJsonContains 的实现
- 无法 json_encode() 数组或 Laravel 集合:“不支持类型