Hello! I have a view which returns a filtered collection. Before filtering the collection, the Eloquent query is paginated. The results are properly paginated, showing only 10 on the page, but the links do not work. It tells me that my Collection does not have the render() function.
// Grab all of the hikes
$hikes = \App\Hike::all();
// Initialize results collection
$results = collect();
// Get the climb rating(s) selected
$climbs = $request->climbs;
// Remember which values have been selected
$selected = [];
// For each climb rating, filter the hikes
if (isset($climbs)) {
foreach ($climbs as $climb) {
$filtered = $hikes->filter(function ($hike) use ($climb) {
return $hike->climb == $climb;
});
// Merge this with our results
$results = $results->merge($filtered);
}
}
return view('hikes.explore')->with('hikes', $results);
@if (method_exists($hikes,'render'))
{{ $hikes->render() }}
@endif
Like I said, the results list 10 at a time, and I can manually go to the next page "?page=2" by typing it in, but the links do not show up. If I don't check for the existence of render() and just let it run, an error message tells me that it doesn't exist.
Can anyone help?
$Pagination = new Illuminate\Pagination\LengthAwarePaginator($results, count($hikes), $perPage, $currentPage);
You are calling the render() method on a collection. But you need to manually create a Pagination like i mentioned above.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community