【发布时间】:2020-03-14 23:25:28
【问题描述】:
这是刀片:
<div class="container">
<table id="myTable" class="table table-bordered sortable">
<thead>
<tr>
<th onclick="sortTable(0)">Companies</th>
<th onclick="sortTable(1)">Devices</th>
<th onclick="sortTable(2)">Vehicles</th>
<th onclick="sortTable(3)">Drivers</th>
</tr>
</thead>
<tbody>
@foreach($items as $company)
<tr>
<td>{{isset($company['company'])?$company['company']->name:''}}</td>
<td>{{isset($company['device'])?$company['device']->type:''}}</td>
<td>{{isset($company['vehicle'])?$company['vehicle']->type:''}}</td>
<td>{{isset($company['driver'])?$company['driver']->name:''}}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
这是控制器:
public function index(Request $request)
{
$items = [];
foreach (Companies::all() as $comp) $items[]['company']=$comp;
foreach (Device::all() as $index => $dev){
if($items[$index]) $items[$index]['device']=$dev;
else $items[]['device']=$dev;
}
foreach (Vehicle::all() as $index => $veh){
if($items[$index]) $items[$index]['vehicle']=$veh;
else $items[]['vehicle']=$veh;
}
foreach (Driver::all() as $index => $dr){
if($items[$index]) $items[$index]['driver']=$dr;
else $items[]['driver']=$dr;
}
return view('/welcome', ['items'=>$items]);
}
我需要在刀片中为这张表进行分页。但我不知道在这种情况下该把命令放在哪里。 我在“return view...$items->paginate”中写道,但那里出现错误。 有什么解决办法吗?
【问题讨论】:
-
请查收,希望这篇博文能帮到你codeshipguru.blogspot.com/2019/10/…
-
根据我对 laravel 的有限经验,您需要为 paginate 提供一个功能参数。
-
@UrsolSolutions 是的,我知道。但是,在“返回”还是在“DB::”中?
-
$items 只是一个数组,它没有分页功能。然而,雄辩的对象返回。所以你可以在一个雄辩的对象上调用它,而不是你自己创建的数组。
-
在父控制器中?
标签: php laravel pagination laravel-blade