gpt4 book ai didi

laravel - 为什么 Pagination laravel 会忽略请求 - skip, take

转载 作者:行者123 更新时间:2023-12-02 03:01:59 24 4
gpt4 key购买 nike

我想使用 skiptake 但分页不起作用。为什么它不起作用?

代码:

    $posts = DB::table('posts')
->orderBy('id','desc')
->skip(9)
->take(3)
->paginate(3);



if ($request->ajax()) {
return ['posts' => view('blog.ajax.index')->with(compact('posts'))->render(),
'next_page' => $posts->nextPageUrl()
];
}

我肯定需要使用分页

最佳答案

您不能同时使用分页和跳过。所以你的替代选择是这样的

$take = 100;
$skip = 9;
$currentPage = Request::get('page', 1);
$poster = DB::table('posts')
->take(100)
->skip($skip + (($currentPage - 1) * $take))
->orderBy('id','desc');

分页尝试

@if (Request::has('page') && Request::get('page') > 1)
<a href="{{ route('some.route', ['page' => Request::get('page') - 1]) }}">Previous page</a>
@endif

@if (Request::has('page'))
<a href="{{ route('some.route', ['page' => Request::get('page') + 1]) }}">Next page</a>
@else
<a href="{{ route('some.route', ['page' =>2]) }}">Next page</a>
@endif

关于laravel - 为什么 Pagination laravel 会忽略请求 - skip, take,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45206337/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com