Ad

Laravel Eloquent Using Paginate With WhereIn

- 1 answer

Hi I have a query that looks roughly like this

Comment::join('users', 'users.id', '=', 'comments.user_id')
    ->whereIn('comments.id', $ids)
    ->paginate(5);

where $ids is an array of comment ids. Changing the paginate to get() works but I want to use paginate as it returns many built-in useful results such as next_page_url etc. So how do I modify the query to utilize both whereIn and paginate together?

Ad

Answer

I found out the issue later on, I forgot to serialize the object before I return the result. A simple toArray() has done the trick.

Ad
source: stackoverflow.com
Ad