doukai2839
doukai2839
2018-06-01 15: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

图片转代码服务由CSDN问答提供 功能建议

当我点击进入第2页时,我会被引导到我网站的主页。 不确定原因。

这是控制器文件中的分页代码:

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

在视图文件中:

 <  code> @if(!isset($ _ REQUEST ['fees'])){{
 $ result-&gt; appends([
'FeesRange'=&gt; request('FeesRange'),
'sortby'=  &gt; request('sortby'),
'location'=&gt; request('location'),
'searchItem'=&gt; request('searchItem'),
'searchLocation'=&gt; request('  searchLocation'),
'criteria'=&gt; request('criteria'),
'search'=&gt; request('search')
]) - &gt; links()
}} 
 @  endif 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongshu7162
    dongshu7162 2018-06-01 15: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()
        ]);
    }
    
    点赞 评论

相关推荐