mahbubrn's avatar

How to get data toArray with pagination

Here is my code.

$orders = Order::with('customer')->withCount('orderItems')->paginate(50)->toArray();

This code return me the blank page. No data return. So here's what I did wrong?

0 likes
3 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

Why are you converting to array in the first place? I cannot think of a case where that is needed

You can try

$orders = Order::with('customer')->withCount('orderItems')->paginate(50);
dd($orders->items()->toArray()); 
1 like
MohamedTammam's avatar

What are you returning in the controller? can you please show all the method code.

1 like
jlrdw's avatar

How will you pass to view? The dd halts execution.

1 like

Please or to participate in this conversation.