Lars-Janssen's avatar

Lazy load with pagination

Hello,

I've got this in my controller:

'reactions' => $message->reaction->load('user', 'user.corporation')->paginate(2)

When I do that ^ I get this error:

Method paginate does not exist.

Is it possible to lazy load + paginate?

0 likes
1 reply
mdecooman's avatar

You have this error because your code does not return the appropriate object type.

// Check what is the result of this and you will understand
dd($message->reaction->load('user', 'user.corporation'));

Check the documentation and you will see there are other ways to accomplish what you want like.

Message::with('reaction')->paginate(10);  

Happy coding

Please or to participate in this conversation.