【问题标题】:Why does the Laravel Pagination always show the same page?为什么 Laravel 分页总是显示相同的页面?
【发布时间】:2018-10-07 23:45:54
【问题描述】:

我正在使用 nginx-Server 和 Laravel 5.6,并想为我的表格使用分页。

这是我的 nginx.conf:

location / {
try_files $uri $uri/ /index.php?$is_args$args;

这是我的控制器:

public function getAllLocations()
{
    $locations = Location::orderBy('name')->paginate(10);

    return view('home', ['locations' => $locations, 'success' => false]);
}

我的看法:

<table class="table table-striped">
    @foreach($locations as $location)    
        <tr id="{{$location->id}}">    
            <td>{{$location->name}}</td>    
        </tr>
    @endforeach

    {{$locations->links()}}

当我单击下一页时,链接正在更改,但显示的数据相同。有什么想法吗?

【问题讨论】:

  • 你的数据有html代码吗?
  • 没有。我想我找到了错误,但我不知道如何解决它。问题是 nginx 总是在 URL 后面创建第二个问号:?%3Fpage=3。任何想法如何解决它?
  • 在你的nginx.conf: 中删除$is_args 怎么样?
  • 我稍后再试试。

标签: php laravel nginx laravel-5 pagination


【解决方案1】:

问题是这一行

try_files $uri $uri/ /index.php?$is_args$args;

你有?,然后是is_argsis_args 如果有 args 则放入 ?,否则为空字符串。因此,当您有 args 时,您是在告诉 nginx 转到 /index.php??args,因此是双问号。

【讨论】:

  • 谢谢。你有什么想法,为什么它在 nginx 中是默认的?
  • 我没有看到你的,我认为这只是一个错字。但是nginx有很多方法可以做,所以不能肯定。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多