Jan 16, 2016
0
Level 3
Custom pagination redirects back to same page
Hi! I'm trying to make custom pagination on a normal collection, but it doesn't seem to be working very well. When I click on the next page I get redirected to the first. All the time. This is where I display the paginated results:
@foreach ($uniqueArticles->chunk(6) as $set)
<div class="row">
@foreach ($set as $article)
<div class="col-md-6 item-search">
@include ('articles.partials.article', ['tnWidth' => '250', 'tnHeight' => '200', 'article' => $article, 'slug' => $article->slug])
</div>
@endforeach
</div>
@endforeach
{!! $paginator->render() !!}
And this is a bit of my SearchController:
$articlesFoundByTag = $this->findArticlesByTag($query);
$articlesFoundByKeyword = $this->findArticlesByKeyword($query);
$allArticles = array_merge($articlesFoundByTag, $articlesFoundByKeyword);
$uniqueArticlesCollection = collect(
$this->arrayUniqueBy($allArticles, function($article) { return $article->id; })
)->sortByDesc('created_at');
$paginator = new LengthAwarePaginator($uniqueArticlesCollection, count($uniqueArticlesCollection), 6);
$paginator->setPath("search?q={$query}&");
$uniqueArticles = $uniqueArticlesCollection->forPage($query, 6);
return view('search.index', ['keyword' => $query,
'uniqueArticles' => $uniqueArticles,
'paginator' => $paginator]);
Please or to participate in this conversation.