[英]How to display data in cell table blade laravel according date value
i need help to displaying data in cell table blade according date data in mysql database.我需要帮助根据 mysql 数据库中的日期数据在单元格表刀片中显示数据。
This the result这是结果
This result that i want我想要的这个结果
data display based on date header基于日期的数据显示 header
this my controller: public function index_filter(Request $request) {这是我的 controller:公共 function index_filter(请求 $request){
$month1 = $request->month1;
$month2 = $request->month2;
$dt = Schedule::where('date', $month1)->value('date');
$dtx = Schedule::where('employee_id', 1)->get();
$dtt = Carbon::parse($dt)->daysInMonth;
$month_label = Carbon::parse($dt)->format('M-Y');
// $data_date = Employee::whereRelation('Schedule', 'date', '=', $month1)->with('Schedule')->get();
// $data_date = DB::table('schedules')
// ->leftJoin('employees', 'schedules.employee_id', '=', 'employees.id')
// ->select('employees.name','schedules.date')
// ->whereBetween('schedules.date', [$month1,$month2])
// ->get();
$data_date = Employee::with(['schedule' => function($q) use($month1,$month2) {
$q->whereBetween('date', [$month1,$month2]);
}])->get();
$name = DB::table('employees')->get();
return view('admin.filter-laporan', [
'dt' => $dt,
'dtt' => $dtt,
'dtx' => $dtx,
'data_date' => $data_date,
'month_label' => $month_label,
'month1' => $month1,
'month2' => $month2,
'name' => $name
]);
}
and this my blade:这是我的刀片:
<table class="table table-striped table-bordered">
<thead>
<tr>
<th rowspan="2" style="text-align: center;">No</th>
<th rowspan="2" style="text-align: center;">Nama</th>
<th colspan="{{ $dtt }}" style="text-align: center;">{{ $month_label }}</th>
</tr>
<tr>
@php
$number = 1;
@endphp
@for ($i = 0; $i < $dtt; $i++)
<th>{{ $number++ }}</th>
@endfor
</tr>
</thead>
<tbody>
@foreach ($data_date as $key => $item)
<tr>
<td>{{ ++$key }}</td>
<td>{{$item->name}}</td>
@foreach ($item->schedule as $items)
@if ($items->status == 'D')
<td style="background-color: green;">{{$items->date }}</td>
@endif
@if ($items->status == 'C')
<td style="background-color: yellow;">X</td>
@endif
@if ($items->status == 'LD')
<td style="background-color: red;">X</td>
@endif
@if ($items->status == '')
<td>-</td>
@endif
@endforeach
</tr>
@endforeach
</tbody>
</table>
if you have any idea for my problem please share to me that way, thank you...如果您对我的问题有任何想法,请以这种方式与我分享,谢谢...
Replace the 2nd @foreach
with this one用这个替换第二个
@foreach
@for ($i = 1; $i <= $dtt; $i++)
@foreach ($item->schedule as $items)
@if(date('d', strtotime($items->date)) == $i)
@if ($items->status == 'D')
<td style="background-color: green;">{{ $items->date }}</td>
@endif
@if ($items->status == 'C')
<td style="background-color: yellow;">X</td>
@endif
@if ($items->status == 'LD')
<td style="background-color: red;">X</td>
@endif
@if ($items->status == '')
<td>-</td>
@endif
@endif
@endforeach
@endfor
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.