are you sure your relationship is set up correctly. All code shown is correct. in your index method, dump the query without the paginate
dd(Forum::with('topics')->get());
and see if you get any errors
Hi,
I've got a strange problem.
When I return this in my ForumController:
public function index()
{
return Forum::with('topics')
->orderBy('created_at', 'DESC')
->paginate(10);
}
I receive the error:
Exception in JsonResponse.php line 65:
Failed calling Illuminate\P agination\LengthAwarePaginator::jsonSerialize()
in JsonResponse.php line 65
at json_encode(array('forums' => object(LengthAwarePaginator)), '0') in JsonResponse.php line 65
at JsonResponse->setData(array('forums' => object(LengthAwarePaginator))) in JsonResponse.php line 50
at JsonResponse->__construct(array('forums' => object(LengthAwarePaginator)), '200', array()) in JsonResponse.php line 27
at JsonResponse->__construct(array('forums' => object(LengthAwarePaginator)), '200', array(), '0') in ResponseFactory.php line 83
at ResponseFactory->json(array('forums' => object(LengthAwarePaginator)), '200') in ForumController.php line 33
The url that for example:
forum.dev/forum?page=1
I've got lots of forum records in my database so it's not empty.
What could be going on?
I think that problem is in order by ...
does this article helps
https://softonsofa.com/tweaking-eloquent-relations-how-to-get-latest-related-model/
Please or to participate in this conversation.