在查询中使用skip
和take
后如何获得总计记录?
代码正常工作:
$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)-> ...
直接在模型上使用paginate()
方法: