doukai2839 2018-06-01 07:01
浏览 75
已采纳

Laravel网站上的分页重定向到主页

When I click to go to Page 2, I get directed to the homepage of my website. Not sure why.

Here's the pagination code in the controller file:

public function paginate($items, $perPage = 15, $page = null, $options = [])
{
    $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
    $items = $items instanceof Collection ? $items : Collection::make($items);
    return new LengthAwarePaginator(
        $items->forPage($page, $perPage), 
        $items->count(), 
        $perPage, 
        $page, 
        $options
    );
}

In the view file:

@if(!isset($_REQUEST['fees'])) {{
    $result->appends([
        'FeesRange' => request('FeesRange'),
        'sortby' => request('sortby'),
        'location' => request('location'),
        'searchItem' => request('searchItem'),
        'searchLocation' => request('searchLocation'),
        'criteria' => request('criteria'),
        'search' => request('search')
    ])->links()
}}
@endif
  • 写回答

1条回答 默认 最新

  • dongshu7162 2018-06-01 07:50
    关注
    $options = [
        'path' => Paginator::resolveCurrentPath()
    ]
    

    Pass this in your options parameter in paginate function.

    Example:

    public function paginate($items, $perPage = 15, $page = null)
    {
        $page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
        $items = $items instanceof Collection ? $items : Collection::make($items);
        return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, [
            'path' => Paginator::resolveCurrentPath()
        ]);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部