相关疑难解决方法(0)

Laravel 5 Paginator生成的链接问题

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

以下是控制器中的一些示例代码:

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

和刀片中的代码:

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

最后是路线中的代码:

Route::get('articles',array('as' => 'article-list','uses' => 'ArticleController@index'));
Run Code Online (Sandbox Code Playgroud)

问题是Laravel会为不同的页面生成错误的URL:example.com/articles/?page = 2 ,with additional/before?.

有一种解决方法可以在将数据传递给视图之前通过调用setPath()来更正URL,现在链接可以正常工作,如下所示:

$articles = Article::latest('published_at')->paginate(3);
$articles->setPath('articles');
return view('articles/index')->with('articles',$articles);
Run Code Online (Sandbox Code Playgroud)

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

谢谢.


环境更新:xampp.

pagination laravel laravel-5

5
推荐指数
1
解决办法
6350
查看次数

标签 统计

laravel ×1

laravel-5 ×1

pagination ×1