【问题标题】:Laravel pagination setpath and appendsLaravel 分页设置路径和附加
【发布时间】:2016-04-13 19:17:08
【问题描述】:

我被 Laravel 分页卡住了。分页中的 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() !!}

【问题讨论】:

    标签: laravel pagination


    【解决方案1】:

    试试这个:

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

    那么在你看来:

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

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

    【讨论】:

      猜你喜欢
      • 2015-09-26
      • 2019-09-30
      • 1970-01-01
      • 2016-04-02
      • 2015-11-27
      • 1970-01-01
      • 2010-09-18
      • 1970-01-01
      • 2019-06-15
      相关资源
      最近更新 更多