获取收藏集总数>>

问题描述 投票:0回答:1

在查询中使用skiptake后如何获得总计记录?

代码正常工作:

$records = Model::where('active', 1)
                 ->skip(($page -1 ) * $max)
                 ->take($max);
// List of records
$data = $records->get()

//Total of all records including the skip records
$total = $records->paginate()->total();

我想这样,但是代码不起作用:

$records = Model::where('active', 1)
                 ->skip(($page -1 ) * $max)
                 ->take($max)->get();

//Not Working 
$total = $records->paginate()->total();

//Not Working 
$total = $records->total();

//Not Working wrong result
$total = $records->count();

如何获取集合中的所有记录?

我使用跳过查询后如何获得总计记录?工作代码:$ records = Model :: where('active',1)-> skip(($ page -1)* $ max)-> ...

php laravel laravel-5 lumen laravel-6
1个回答
0
投票

直接在模型上使用paginate()方法:

© www.soinside.com 2019 - 2024. All rights reserved.