Lars-Janssen's avatar

Pagination eror

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?

0 likes
5 replies
clay's avatar

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

Lars-Janssen's avatar

@clay That returns the expected result. So strange really no idea what could be going on here.

clay's avatar

interesting. following this thread. if you figure out what is happening, please update. thanks

Lars-Janssen's avatar

@tomi thanks just found the problem. Had jwt auth tymen wrong configured.

Took me 2 hours before I found it.... :(

Please or to participate in this conversation.