I had a strange problem when I tried to use Paginator in Laravel 5. The pagination data and information were prepared, but when I called $ model-> render () in a click, the page links were just wrong.
Here is a sample code in the controller:
public function index() { $articles = Article::latest('published_at')->paginate(3); return view('articles/index')->with('articles',$articles); }
And the code in a click:
{!! $articles->render() !!}
Finally, the code in the routes:
Route::get('articles',array('as' => 'article-list','uses' => ' ArticleController@index '));
The problem is that Laravel is generating the wrong URLs for different pages: example.com/articles/?page=2 , with extra / before ?.
There is a way around the URL by calling setPath () before passing the data for viewing, and the links now work like this:
$articles = Article::latest('published_at')->paginate(3); $articles->setPath('articles'); return view('articles/index')->with('articles',$articles);
But are there any other options for creating the right page links in Laravel 5, and did I miss something?
Thanks.
Environment update: xampp.
source share