A Collection and a Paginator doesn't have the same structure. Not sure if your ChatTransformer can work the same way on both. Can you dump the collection (first case) and the paginator (second case) and the content of your ChatTransformer ?
Dec 28, 2014
5
Level 2
adding Pagination messes up the output
hi,
I'm trying to get some chats from my DB. but when adding pagination it messes up the output:
So by using the following code, I get the following output:
code
echo 'First ouptut';
$chats = Auth::User()->Chats;
var_dump(ChatTransformer::transformCollection($chats));
echo 'Second ouptut';
$limit = Input::get( 'limit', '5' );
$chats = Auth::User()->Chats()->paginate( $limit );
var_dump(ChatTransformer::transformCollection($chats));
output
First ouptut
array (size=2)
0 =>
array (size=4)
'chat_id' => int 9
'title' => string 'TestChat' (length=8)
'messages' =>
array (size=1)
0 =>
array (size=6)
...
'users' =>
array (size=3)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
2 =>
array (size=3)
...
1 =>
array (size=4)
'chat_id' => int 10
'title' => string 'second Chat' (length=11)
'messages' =>
array (size=0)
empty
'users' =>
array (size=3)
0 =>
array (size=3)
...
1 =>
array (size=3)
...
2 =>
array (size=3)
...
Second ouptut
array (size=2)
0 =>
array (size=4)
'chat_id' => int 25
'title' => string 'TestChat' (length=8)
'messages' =>
array (size=0)
empty
'users' =>
array (size=0)
empty
1 =>
array (size=4)
'chat_id' => int 28
'title' => string 'second Chat' (length=11)
'messages' =>
array (size=0)
empty
'users' =>
array (size=0)
empty
Notice how the Id's have changed and the output of the users and messages have gone emtpy? any reason why that is happeing?
Note: The id's have change to: chat_users table (that keeps track of what users belongs to what chat group)
Level 2
Believe it or not it just started working today, didn't change anything. But now it's showing as it should.
Thanks for the help anyway!
1 like
Please or to participate in this conversation.