首页 文章

Laravel分页setpath和追加

提问于
浏览
1

我被Laravel Pagination困住了 . 分页中的URL始终包含2个问号 .

http://domain.com/?direction=asc?page=2

$posts = Post::paginate(10)
        ->setPath(route('post-admin', [
            'direction' => $direction
          ]))

在视图中:

{!! $post->render() !!}

我也尝试过:

{!! $post->appends([
    'direction' => $direction
])->render() !!}

1 回答

  • 6

    试试这个:

    $posts = Post::paginate(10)
            ->setPath(route('post-admin'))
            ->appends('direction', $direction);
    

    然后在你看来:

    {!! $posts->render() !!}
    

    确保不要调用 all() 方法,而是直接在模型上调用 paginate() .

相关问题