Laravel分页setpath和追加

poa*_*oas 1 pagination laravel

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

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

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

在视图中:

{!! $post->render() !!}
Run Code Online (Sandbox Code Playgroud)

我也尝试过:

{!! $post->appends([
    'direction' => $direction
])->render() !!}
Run Code Online (Sandbox Code Playgroud)

Jer*_*ten 9

试试这个:

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

然后在你看来:

{!! $posts->render() !!}
Run Code Online (Sandbox Code Playgroud)

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