I've noticed a typo in the code I typed above - I actually use
$activities = Paginator::make($activities->all(), count($activities), 10);
Here is a screenshot of the start of the output.
Did you try
$activities = Paginator::make($activities, count($activities), 10);
$items = $activities->count();
dd($items);
Is it got 10 items ?
dd($activities->toArray());
Would this work ?
// controller
$activities = Activity::paginate(10);
return View::make('activities.index', compact('activities'));
// view
@foreach($activities as $activity)
// Output activities
@endforeach
{{ $activities->links() }}
This should return 10 activities and display pagination.
lainga9 said:
I am doing something simple like the following:
// Controller $activities = Activity::all(); $activities = Paginator::make($activities, count($activities), 10); return View::make('activities.index', compact('activities')); // // View @foreach($activities as $activity) // Output activities @endforeach {{ $activities->links() }}
This works but whenever I try
dd($activities);
the whole browser crashes!
I console.logged the returned data through an ajax request and eventually it spat out about 1.4 MILLION lines of code.
It basically returned absolutely everything Laravel contains, all routes, classes, filters - at the bottom of which where the actual activities and pagination info.
Any idea why this would be happening?
Cheers
This is because dd uses var_dump(), which outputs everything about an object, and that includes references to other objects. So if you have a circular reference, IE, Object A -> Object B -> Object C -> Object A, it will cause an infinite loop, eventually crashing the browser or causing PHP to time out.
iClosedz said:
Did you try
$activities = Paginator::make($activities, count($activities), 10); $items = $activities->count(); dd($items);
Is it got 10 items ?
yes it returns (int) 10.
pmall said:
dd($activities->toArray());
Would this work ?
Yes this returns an array of items but I was trying to use dd to inspect the returned object.
pogachar said:
// controller $activities = Activity::paginate(10); return View::make('activities.index', compact('activities')); // view @foreach($activities as $activity) // Output activities @endforeach {{ $activities->links() }}
This should return 10 activities and display pagination.
This does indeed work as I mentioned but I use dd a lot to inspect returned data and was just wondering why it wasn't possible.
thepsion5 said:
This is because dd uses var_dump(), which outputs everything about an object, and that includes references to other objects. So if you have a circular reference, IE, Object A -> Object B -> Object C -> Object A, it will cause an infinite loop, eventually crashing the browser or causing PHP to time out.
So does this mean it is not possible to inspect a Paginator instance? Seems odd when I've been able to inspect everything else in laravel!
thepsion5 said:
This is because dd uses var_dump(), which outputs everything about an object, and that includes references to other objects. So if you have a circular reference, IE, Object A -> Object B -> Object C -> Object A, it will cause an infinite loop, eventually crashing the browser or causing PHP to time out.
So does this mean it is not possible to inspect a Paginator instance? Seems odd when I've been able to inspect everything else in laravel!
Ah mentioned by thepsion5 there will be an infinite loop if your objects have circular references. Thats why using ->toArray() is useful to inspect the values of Eloquent objects.
Ah rite ok I understand. Thanks for all your help!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community