Php Laravel-如何将采集数据加载到表中?
我用一个名为$group\u months的变量来存储数据,下面是我添加($group\u months)时使用的变量。箭头前的数字代表月份,箭头后的数字代表时间。因此10月=10月Php Laravel-如何将采集数据加载到表中?,php,laravel,html-table,eloquent,Php,Laravel,Html Table,Eloquent,我用一个名为$group\u months的变量来存储数据,下面是我添加($group\u months)时使用的变量。箭头前的数字代表月份,箭头后的数字代表时间。因此10月=10月 Collection {#187 ▼ #items: array:4 [▼ "Comp Time Used" => Collection {#292 ▼ #items: array:3 [▼ 10 => "12:00:00" 11 => "0
Collection {#187 ▼
#items: array:4 [▼
"Comp Time Used" => Collection {#292 ▼
#items: array:3 [▼
10 => "12:00:00"
11 => "09:00:00"
"01" => "12:00:00"
]
}
"Vacation Time Used" => Collection {#322 ▼
#items: array:1 [▼
11 => "04:00:00"
]
}
"Sick Time" => Collection {#325 ▼
#items: array:1 [▼
10 => "03:15:00"
]
}
"OT Accrued" => Collection {#316 ▼
#items: array:1 [▼
10 => "12:00:00"
]
}
]
}
我想使用这些数据并填写如下表格:
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Overtime Hours</th>
<th scope="col">Compensation Hours</th>
<th scope="col">Vacation</th>
<th scope="col">Personal Hours</th>
<th scope="col">Sick Hours</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jan</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
</tr>
<tr>
<th scope="row">Feb</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Mar</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Apr</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">May</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Jun</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Jul</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Aug</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Sep</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Oct</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Nov</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Dec</th>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
这应该让你开始。在将其发送到视图之前,我将合并控制器中的所有时间。这将使它变得容易。这里,如果该月存在数组键,它将打印该月的值。如果它不存在,它不会抛出错误,因为
array\u key\u exists
只会返回false而不执行其他操作
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Overtime Hours</th>
<th scope="col">Compensation Hours</th>
<th scope="col">Vacation</th>
<th scope="col">Personal Hours</th>
<th scope="col">Sick Hours</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jan</th>
<td></td>
<td></td>
@if(array_key_exists(1, $group_months['Comp Time Used']))
<td>{{$group_months['Comp Time Used'][1]</td>
@else
<td>No time off used</td>
@endif
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Feb</th>
<td></td>
<td></td>
@if(array_key_exists(2, $group_months['Comp Time Used']))
<td>{{$group_months['Comp Time Used'][2]</td>
@else
<td>No time off used</td>
@endif
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
月
加班时间
补偿时间
假期
私人时间
病假
简
@如果(数组\密钥\存在(1,$group\月['Comp Time Used']))
{{$group_月['Comp Time Used'][1]
@否则
没有休息时间
@恩迪夫
二月
@如果(数组\密钥\存在(2,$group\月['Comp Time Used']))
{{$group_月['Comp Time Used'][2]
@否则
没有休息时间
@恩迪夫
您的$group\u months是否始终包含4个值?休假、病假、加班、薪酬?如果员工没有任何与该细节相关的信息,它是否只返回空数组或根本没有该参数的数组?是的,它将始终包含这4个值,如果他们没有将加班时间记录到数据库中,则转储数据不会显示OT的数组。是否有任何方法可以将其存储为数组而不是集合?可能使用toArray()命令方法?或者其他代码是否要求对象为集合?好的,我现在将其存储为数组。更新了opperfect。最后一个问题。一个月是否会有多个条目?那么数组是否会包含10=>'12'和另一个十月值?或者在将其存储到数组中之前是否将所有月份的数据合并在一起?谢谢,我将我试试这个。我感谢你的帮助。没问题。如果它有效,请给我一个向上投票和一个“标记为正确”。始终感谢:我也意识到我在我的if语句中漏掉了一个右括号,现在检查更新的代码。谢谢你,我想我可以建立这个!
<table class="table table-striped table-sm">
<thead>
<tr>
<th scope="col">Month</th>
<th scope="col">Overtime Hours</th>
<th scope="col">Compensation Hours</th>
<th scope="col">Vacation</th>
<th scope="col">Personal Hours</th>
<th scope="col">Sick Hours</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Jan</th>
<td></td>
<td></td>
@if(array_key_exists(1, $group_months['Comp Time Used']))
<td>{{$group_months['Comp Time Used'][1]</td>
@else
<td>No time off used</td>
@endif
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">Feb</th>
<td></td>
<td></td>
@if(array_key_exists(2, $group_months['Comp Time Used']))
<td>{{$group_months['Comp Time Used'][2]</td>
@else
<td>No time off used</td>
@endif
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>