Laravel 5分页问题

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] => shivani.ruhela@hotmail.com
                            [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] => shivani2.ruhela@hotmail.com
                            [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.

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

Try this.. it might work for you

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;
}

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;
}