Laravel DB表分页方法

Is it possible to use native pagination on the DB::table()->get() method? Now, I have 3000+ records in a specific table, and I'd like to trigger pagination of 1000 records at a time.

这是我有的方法:

public function refresh()
{
    $records = DB::table('employees')->get();

    foreach ($records as $record)
    {
        $record = $this->getRecord($record);
        $record->updated_at = date('Y-m-d H:i:s');
        $record->save();
    }

    return $record;
}

谢谢大家!

评论
  • Antoi
    Antoi 回复

    Yes! you can do that using paginate function $records = DB::table('employees')->paginate(1000); more here

  • 凉人夢
    凉人夢 回复

    将您的查询放入集合函数

    eg. $record
    
    return collection($record)->paginate(10);