我想使用像这样的刀片foreach
循环来创建动态表HTML:
合并名称,父亲姓名和类型相同的行。
我已经创建了表,但是它使第一条记录完成,而重置未完成,而没有合并像这样的行:
我的观点
<tbody>
@php
$rowid = 0;
$rowspan = 0;
@endphp
@foreach($result as $key => $data)
@php
$rowid += 1
@endphp
<tr>
@if ($key == 0 || $rowspan == $rowid)
@php
$rowid = 0;
$rowspan = $data->driver_name;
@endphp
<td id="" rowspan="{{$result->count()}}"></td>
<td id="" rowspan="{{$result->count()}}">{{$data->driver_name}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->father_name}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->vehicle_type}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->plate_no}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->serial_number}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->description}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->created_at}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->order_number}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->export_number}}</td>
@endif
<td id="">{{$data->buy_parts}}</td>
<td id="">{{$data->quantity}}</td>
<td id="">{{$data->per_item_price}}</td>
<td id="">{{$data->total_price}}</td>
@if ($key == 0 || $rowspan == $rowid)
@php
$rowid = 0;
$rowspan = $data->driver_name;
@endphp
<td id="" rowspan="{{$result->count()}}">{{$data->export_date}}</td>
<td id="" rowspan="{{$result->count()}}">{{$data->remarks}}</td>
@endif
</tr>
@endforeach
</tbody>
我的控制器:
public function repair_parts()
{
$result=DB::table('parts_orders as a')
->select('b.emp_id','c.name as driver_name','c.father_name','d.vehicle_type','d.plate_no','b.id as serial_number'
,'b.description','b.created_at','a.order_number','a.export_number','a.buy_parts','a.per_item_price','a.quantity'
,'a.total_price','a.export_date','a.remarks')
->join('repair_cars as b','a.repair_id','=','b.id','left')
->join('drivers as c','b.emp_id','=','c.emp_id','left')
->join('vehicles as d','b.vechcal_id','=','d.plate_no','left')
->join('locations as e','b.location_id','=','e.id','left')
->get();
return view('Reports/repair_parts_report',compact('result'));
}
答案 0 :(得分:0)
您可以尝试这种方式。
数据数组
@php
$rows = [
[
'remarks' => 'remark',
'date' => '2019-07-09',
'total' => [100,200,300],
'quantity' => [100,200,300],
'partname' => ['a','b','c'],
'number' => '123412',
'ordernumber' => 'RNX123',
'orderdate' => '2019-07-09',
'desc' => 'some descriptioin',
'saledate' => '2019-07-09',
'datenumber' => '99884',
'type' => 'test',
'father' => 'father',
'name' => 'name',
],
[
'remarks' => 'remark',
'date' => '2019-07-09',
'total' => [100,200,300],
'quantity' => [100,200,300],
'partname' => ['a','b','c'],
'number' => '123412',
'ordernumber' => 'RNX123',
'orderdate' => '2019-07-09',
'desc' => 'some descriptioin',
'saledate' => '2019-07-09',
'datenumber' => '99884',
'type' => 'test',
'father' => 'father',
'name' => 'name',
],
]
@endphp
叶片部分。
<table border="1">
<tr>
<th>Remarks</th>
<th>Date</th>
<th>Total</th>
<th>Quantity</th>
<th>Part Name</th>
<th>Number</th>
<th>Order Number</th>
<th>Order Date</th>
<th>Description</th>
<th>Sale Date</th>
<th>Date Number</th>
<th>Type</th>
<th>
<table border="1">
<tr><th colspan="2"> Urdu</th></tr>
<tr>
<th>Father</th>
<th>Name</th>
</tr>
</table>
</th>
<th>#</th>
</tr>
<tbody>
@foreach($rows as $key => $row)
<tr>
<td> {{$row['remarks']}}</td>
<td> {{$row['date']}}</td>
<td>
@foreach($row['total'] as $total)
<table border="1">
<tr>
<td>{{ $total}}</td>
</tr>
</table>
@endforeach
</td>
<td>
@foreach($row['quantity'] as $quantity)
<table border="1">
<tr>
<td>{{ $quantity}}</td>
</tr>
</table>
@endforeach
</td>
<td>
@foreach($row['partname'] as $partname)
<table border="1">
<tr>
<td>{{ $partname}}</td>
</tr>
</table>
@endforeach
</td>
<td> {{$row['number']}}</td>
<td> {{$row['ordernumber']}}</td>
<td> {{$row['orderdate']}}</td>
<td> {{$row['desc']}}</td>
<td> {{$row['datenumber']}}</td>
<td> {{$row['type']}}</td>
<td> {{$row['father']}}</td>
<td> {{$row['name']}}</td>
<td> {{ $key+1}}</td>
</tr>
@endforeach
</tbody>
</table>
OutPut。
希望您能从中得到一些启发。