Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

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.

http://glasgoweb.net/output.png

Last updated 2 years ago.
0

Did you try

$activities = Paginator::make($activities, count($activities), 10);
$items = $activities->count();
dd($items);

Is it got 10 items ?

Last updated 2 years ago.
0
dd($activities->toArray());

Would this work ?

Last updated 2 years ago.
0
// 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.

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

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!

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Ah rite ok I understand. Thanks for all your help!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lainga9 lainga9 Joined 12 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.