hungtranm's avatar

Method Illuminate\Database\Eloquent\Collection::links not exist

Hi, I'm a new in laravel, I got an issue with creating links pagination. Please help. This is my code:

public static function search($params = []) {
        $query = self::paginate(10);

        if (isset($params['category_id']) && $params['category_id']) {
            return $query->where('category_id', $params['category_id']);
        }

        return $query;
    }

The code work Ok, but when I call the function {{ $feeds->links() }} in the view, it raise an error: Method Illuminate\Database\Eloquent\Collection::links not exist. I also following the instruction: https://laravel.com/docs/5.8/pagination#displaying-pagination-results. Do I miss any step ?

Please help to fix this. Thank you.

0 likes
2 replies
adalessa's avatar

Since the error came from a collection I think you mat be wrongly calling the get method ?. The paginate should be last function before returning to the view since it executes the query inside. so you should change your code a bit for that.

hungtranm's avatar

Hi,

You're absolutely right. I call paginate at the last chain and it works.

Many thanks.

Please or to participate in this conversation.