出于某种原因{{$ items-> links()}}没有做任何事情。Laravel - 没有出现分页链接
此问题的直接原因是$ items-> getLastPage()返回0. Same $ items-> getTotal()。
我可以更改网页中的页面参数,它工作正常 - 它进入正确的页面。 但是$ items-> getCurrentPage()在每个页面上返回1。
分页对我来说完全适用于其他模型,只是这个问题给我带来了问题。
另外它似乎工作正常,当我手动创建paginator,但我想能够访问模型中的一些方法,所以我想使用Eloquent模型,而不是原始数组。
编辑: 代码:
$records = EventLog::byObject($model, $id)->paginate(10);
static public function byObject($model, $id)
{
$records = DB::select([query], [params]);
return self::getHistory($records, $model);
}
static public function getHistory($records, $model = '')
{
$ids = array();
foreach ($records as $record) {
array_push($ids, (int)$record->id);
}
$history = array();
if (count($ids)) {
$history = EventLog::whereRaw('id IN (' . implode(',', array_fill(0, count($ids), '?')) . ')', $ids)
->with('creator')
->with(array('eventfields' => function($query)
{
$query->whereRaw('field NOT LIKE \'%_id\'');
}))
->orderBy('event_logs.created_at')
->orderByRaw('(CASE WHEN eventable_type=? THEN 0 ELSE 1 END)', array($model))
->orderByRaw('(CASE WHEN parent_type=? THEN 0 ELSE 1 END)', array($model));
}
return $history;
}
返回$历史有正确的类型,显示正常,但分页不工作的一些原因。
我试图用
{{ $records->links(); }}
感谢
我们需要你的代码,以帮助您。请在您设置分页的地方发布代码。 – chris342423
@ chris342423我刚刚添加了我的代码。 – GrumpyHat