Loach's avatar
Level 11

Running filter on Eloquent Collection removes pagination links() method?

I have the following code.

$results = $user->paginate(3);
        if(\Auth::check()){
            $results = $results->filter(function($item) {
              return $item->id != \Auth::user()->id;
        });
        }

On my blade page I get an error about $results->links() method not existing.

If i just run this code I do not get that error.

$results = $user->paginate(3);
0 likes
1 reply
staudenmeir's avatar
Level 24

Try this:

$results->setCollection($results->filter(function($item) {
      return $item->id != \Auth::user()->id;
}));

Please or to participate in this conversation.