@Akeno Which version of the framework you're using?
Many-to-many -> Pagination with pivot table data
Hi,
I have a many-to-many relation:
locations
messages
location_messages
Now, I want to paginate all of the messages from a Location:
$location->messages()->paginate(10);
That works but there is one problem: Inside my pivot table, there is some important data I need. The way from above does get this data, but it does not put it within a "->pivot" attribute. Normally I can access pivot data like this:
$messages = $location->load('messages')->messages;
$messages->pivot->pivotData;
But if I work with pagination, the pivot data is put as attribute from Message, not as attribute of pivot:
$messages = $location->messages()->paginate(10);
$messages->items()[0]->pivotData // items()[0] is a Message model
So I don't need the "->pivot->" to access it. That would be fine, but I have several methods that use "->pivot->" to access the data. And they don't work when I use pagination to get the messages.
I could manually copy these to a pivot attribute, but that's not really convenient and can cause trouble I think.
Any ideas? Thank you :)
Please or to participate in this conversation.