Support the ongoing development of Laravel.io →
Eloquent Views Installation

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.

A bit from my Controller

    // 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);

The bit from my view with the pagination links

 @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?

Last updated 2 years ago.
0
$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.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

beckrecca beckrecca Joined 22 Oct 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.