Laravel 5分页问题

时间:2015-04-28 07:29:55

标签: php laravel pagination

我正在使用laravel 5分页并遇到一些问题。

这是我的代码DB::table('users')->paginate(2),它返回LengthAwarePaginator的对象,如下所示:

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
)

我的问题是我想迭代这个对象并检索包含数据库数据的项目对象,即名称,电子邮件等。

但我不知道如何从返回的对象访问受保护的成员。

3 个答案:

答案 0 :(得分:1)

Sub testOLE()
mPath = ActiveWorkbook.Path

For Each obj In Worksheets(1).OLEObjects
 If obj.Name = "TEST" Then
 obj.Verb
 obj.Object.Activate
 obj.Object.SaveAs mPath & "TEST_success.xlsx"
 obj.Object.Close
End If
 i = i + 1
Next
End Sub

试试这个..它可能适合你

答案 1 :(得分:1)

你可以像使用数组那样使用返回的对象:

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

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

答案 2 :(得分:0)

您可以使用与访问任何其他集合相同的方式访问分页对象。例如

"'invitedfriend='" + invited