laravel - Laravel 5 分页生成链接的问题

标签 laravel pagination laravel-5

我在 Laravel 5 中尝试使用分页器时遇到了一个奇怪的问题。
数据和分页信息已准备好,但是当我在 Blade 中调用 $model->render() 时,页面链接完全错误。

这是 Controller 中的一些示例代码:

public function index()
{
    $articles = Article::latest('published_at')->paginate(3);
    return view('articles/index')->with('articles',$articles);
}

Blade 中的代码:
{!! $articles->render() !!}

最后是路由中的代码:
Route::get('articles',array('as' => 'article-list','uses' => 'ArticleController@index'));

问题是 Laravel 为不同的页面生成了错误的 url,例如: example.com/articles/?page=2 , 在 ? 之前加上/。

有一种解决方法可以通过在将数据传递给 View 之前调用 setPath() 来更正 url,并且链接现在可以工作,如下所示:
$articles = Article::latest('published_at')->paginate(3);
$articles->setPath('articles');
return view('articles/index')->with('articles',$articles);

但是还有其他选项可以在 Laravel 5 中生成正确的页面链接而我错过了什么吗?

谢谢你。

环境更新:xampp。

最佳答案

在您的 Blade 中使用此代码,

{!! str_replace('/?', '?', $articles->render()) !!}

此代码生成正确的网址。

关于laravel - Laravel 5 分页生成链接的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28424522/

相关文章:

php - 子域路由覆盖并运行 web.php 中的最后一个子域

php - 接受两个不同的模型实例作为函数参数 php

php - Laravel 5.2.31 Socialite 证书 ssl 错误

php - Laravel 请求具有复杂 url 的通配符

javascript - AngularJS渲染更新记录+Laravel后端

laravel - 如何测试外部API?

c# - 向 gridview 添加分页 asp.net

php - active class 如何实现分页

twitter-bootstrap - Twitter Bootstrap 3 的 Laravel 4 分页错误

heroku - SQLSTATE[HY000] [2002] 没有这样的文件或目录(SQL : select * from information_schema. 表,其中 table_schema = 和 table_name = 迁移)