1

I am working with laravel 5 pagination and getting some problems.

Here is my code DB::table('users')->paginate(2) and it returns an object of LengthAwarePaginator Like this :

Illuminate\Pagination\LengthAwarePaginator Object
(
    [total:protected] => 4
    [lastPage:protected] => 2
    [items:protected] => Illuminate\Support\Collection Object
        (
            [items:protected] => Array
                (
                    [0] => stdClass Object
                        (
                            [id] => 3
                            [Name] => shivani
                            [email] => [email protected]
                            [password] => $2y$10$iD1by60rSBvrMjuqwmYLseNIrd4jmvK8sXUEYiXfDjJVcBD02jEbK
                            [updated_at] => 2015-04-27 05:17:34
                            [created_at] => 2015-04-27 05:17:30
                            [remember_token] => guVL5RdcmRXedSBMsfSZSlCeFPfRjEq8vSNQNjtED2ytBHaPCZ3N8G3dmj6C
                        )

                    [1] => stdClass Object
                        (
                            [id] => 4
                            [Name] => shivani
                            [email] => [email protected]
                            [password] => $2y$10$iD1by60rSBvrMjuqwmYLseNIrd4jmvK8sXUEYiXfDjJVcBD02jEbK
                            [updated_at] => 2015-04-27 05:17:34
                            [created_at] => 2015-04-27 05:17:30
                            [remember_token] => guVL5RdcmRXedSBMsfSZSlCeFPfRjEq8vSNQNjtED2ytBHaPCZ3N8G3dmj6C
                        )

                )

        )

    [perPage:protected] => 2
    [currentPage:protected] => 1
    [path:protected] => http://localhost/shivani/public/check/user-list
    [query:protected] => Array
        (
        )

    [fragment:protected] => 
    [pageName:protected] => page
)

My problem is that I want to iterate through this object and retrieve items object that holds database data i.e. name , email etc.

But I don't know how to access protected members from the returned object.

3 Answers 3

1
$data = DB::table('users')->paginate(2)->toArray()

Try this.. it might work for you

Sign up to request clarification or add additional context in comments.

1 Comment

I got it working. But did'nt get page links using $user->render(). Please help.
1

You can just use the returned object like it where an array:

$users = DB::table('users')->paginate(2);

foreach($users as $user){
    echo $user->email;
}

Comments

0

You can access paginated objects same way you can access any other collection. For example

foreach(DB::table('users')->paginate(2) as $object) {
   echo $object->name;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.