weixin_33704591 2014-07-10 16:28 采纳率: 0%
浏览 21

与Laravel分页

I am using a system of infinite scroll pagination with Laravel and Ajax. It works like:

  • I load the first 10 results, simply using Book::orderBy('created_at')->paginate(5);
  • Then, via Ajax I call to another function which must return the next 5 values. But I don't want the first 5 values, only the 5 new ones.

So, I am looking for something like:

    $shown=10;
    $showPerPage=5;
   //The function that I am looking for
    Book::orderBy('created_at')->paginateFrom(10,5)

This would load the five books after the number 10. I've seen Paginator::make(), but I has two problems: first, it requires all the existing values, so I have to ask the db for every result, which is not very efficient, and second, I cannot pass an array to that funcion because Laravel return an object when you use ->get().

Any idea how could I do it?

  • 写回答

1条回答 默认 最新

  • csdn产品小助手 2014-07-10 16:57
    关注

    I think this could solve:

    $shown=10;
    $showPerPage=5;
    Book::orderBy('created_at')->skip($shown)->take($showPerPage)->get();
    

    Basically the skip method adds the OFFSET clause and the take adds the LIMIT one.

    Source: http://laravel.com/docs/queries

    评论

报告相同问题?

悬赏问题

  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法