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

时间:2018-06-01 15:01:26

标签: php laravel laravel-5 pagination

当我点击进入第2页时,我会被引导到我网站的主页。不知道为什么。

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

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
    );
}

在视图文件中:

@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 个答案:

答案 0 :(得分:1)

$options = [
    'path' => Paginator::resolveCurrentPath()
]

paginate函数的options参数中传递此内容。

示例:

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()
    ]);
}