Car*_*ter 5 pagination laravel laravel-5
当我尝试在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.
Vin*_* VT 10
在刀片中使用此代码,
{!! str_replace('/?', '?', $articles->render()) !!}
Run Code Online (Sandbox Code Playgroud)
此代码生成正确的URL.
| 归档时间: |
|
| 查看次数: |
6350 次 |
| 最近记录: |