Laralvel 5.2 Pagination不会从params返回

时间:2016-07-18 14:00:51

标签: php laravel-5.2

我正在做这样的事情

$users = CompanyModel::paginate(5);
print_r($users);exit;

当我打印它时,它将打印" Illuminate \ Pagination \ LengthAwarePaginator对象" ,它将返回para,例如total,perPage,currentPage等。

现在我需要param,就像我将用于前端的分页一样。

请帮助!!

我的回答:

 Illuminate\Pagination\LengthAwarePaginator Object
 (
[total:protected] => 21
[lastPage:protected] => 5
[items:protected] => Illuminate\Database\Eloquent\Collection Object
    (
        [items:protected] => Array
            (
                [0] => DayJibe\DAL\Company\Models\CompanyModel Object
                    (
                        [table:protected] => companies
                        [fillable:protected] => Array
                            (
                                [0] => company_name
                                [1] => user_first_name
                                [2] => user_email
                                [3] => plan_name
                                [4] => total_users
                                [5] => monthly_payment_amount
                                [6] => term_ending
                                [7] => sign_up_date
                                [8] => receive_special_offers_emails
                                [9] => time_spent_logged_in
                                [10] => storage_used
                            )

                        [connection:protected] => 
                        [primaryKey:protected] => id
                        [keyType:protected] => int
                        [perPage:protected] => 15
                        [incrementing] => 1
                        [timestamps] => 1
                        [attributes:protected] => Array
                            (
                                [id] => 1
                                [company_name] => JohnSmithConsulting
                                [user_first_name] => John
                                [user_email] => admin@gmail.com
                                [plan_name] => Basic
                                [total_users] => 4
                                [monthly_payment_amount] => 10
                                [term_ending] => 2016-01-02 00:00:00
                                [sign_up_date] => 2015-01-02 00:00:00
                                [receive_special_offers_emails] => Y
                                [time_spent_logged_in] => 15
                                [storage_used] => 100
                                [created_at] => 2016-07-14 11:37:51
                                [updated_at] => 2016-07-14 11:37:51
                            )

                        [original:protected] => Array
                            (
                                [id] => 1
                                [company_name] => JohnSmithConsulting
                                [user_first_name] => John
                                [user_email] => admin@gmail.com
                                [plan_name] => Basic
                                [total_users] => 4
                                [monthly_payment_amount] => 10
                                [term_ending] => 2016-01-02 00:00:00
                                [sign_up_date] => 2015-01-02 00:00:00
                                [receive_special_offers_emails] => Y
                                [time_spent_logged_in] => 15
                                [storage_used] => 100
                                [created_at] => 2016-07-14 11:37:51
                                [updated_at] => 2016-07-14 11:37:51
                            )

                        [relations:protected] => Array
                            (
                            )

                        [hidden:protected] => Array
                            (
                            )

                        [visible:protected] => Array
                            (
                            )

                        [appends:protected] => Array
                            (
                            )

                        [guarded:protected] => Array
                            (
                                [0] => *
                            )

                        [dates:protected] => Array
                            (
                            )

                        [dateFormat:protected] => 
                        [casts:protected] => Array
                            (
                            )

                        [touches:protected] => Array
                            (
                            )

                        [observables:protected] => Array
                            (
                            )

                        [with:protected] => Array
                            (
                            )

                        [morphClass:protected] => 
                        [exists] => 1
                        [wasRecentlyCreated] => 
                    )

                [1] => DayJibe\DAL\Company\Models\CompanyModel Object
                    (
                        [table:protected] => companies
                        [fillable:protected] => Array
                            (
                                [0] => company_name
                                [1] => user_first_name
                                [2] => user_email
                                [3] => plan_name
                                [4] => total_users
                                [5] => monthly_payment_amount
                                [6] => term_ending
                                [7] => sign_up_date
                                [8] => receive_special_offers_emails
                                [9] => time_spent_logged_in
                                [10] => storage_used
                            )

                        [connection:protected] => 
                        [primaryKey:protected] => id
                        [keyType:protected] => int
                        [perPage:protected] => 15
                        [incrementing] => 1
                        [timestamps] => 1
                        [attributes:protected] => Array
                            (
                                [id] => 2
                                [company_name] => James Engineering
                                [user_first_name] => James
                                [user_email] => James@gmail.com
                                [plan_name] => Enterprise
                                [total_users] => 50
                                [monthly_payment_amount] => 250
                                [term_ending] => 2016-04-05 00:00:00
                                [sign_up_date] => 2016-01-02 00:00:00
                                [receive_special_offers_emails] => N
                                [time_spent_logged_in] => 25
                                [storage_used] => 250
                                [created_at] => 2016-07-15 06:33:34
                                [updated_at] => 2016-07-15 06:33:34
                            )

                        [original:protected] => Array
                            (
                                [id] => 2
                                [company_name] => James Engineering
                                [user_first_name] => James
                                [user_email] => James@gmail.com
                                [plan_name] => Enterprise
                                [total_users] => 50
                                [monthly_payment_amount] => 250
                                [term_ending] => 2016-04-05 00:00:00
                                [sign_up_date] => 2016-01-02 00:00:00
                                [receive_special_offers_emails] => N
                                [time_spent_logged_in] => 25
                                [storage_used] => 250
                                [created_at] => 2016-07-15 06:33:34
                                [updated_at] => 2016-07-15 06:33:34
                            )

                        [relations:protected] => Array
                            (
                            )

                        [hidden:protected] => Array
                            (
                            )

                        [visible:protected] => Array
                            (
                            )

                        [appends:protected] => Array
                            (
                            )

                        [guarded:protected] => Array
                            (
                                [0] => *
                            )

                        [dates:protected] => Array
                            (
                            )

                        [dateFormat:protected] => 
                        [casts:protected] => Array
                            (
                            )

                        [touches:protected] => Array
                            (
                            )

                        [observables:protected] => Array
                            (
                            )

                        [with:protected] => Array
                            (
                            )

                        [morphClass:protected] => 
                        [exists] => 1
                        [wasRecentlyCreated] => 
                    )

                [2] => DayJibe\DAL\Company\Models\CompanyModel Object
                    (
                        [table:protected] => companies
                        [fillable:protected] => Array
                            (
                                [0] => company_name
                                [1] => user_first_name
                                [2] => user_email
                                [3] => plan_name
                                [4] => total_users
                                [5] => monthly_payment_amount
                                [6] => term_ending
                                [7] => sign_up_date
                                [8] => receive_special_offers_emails
                                [9] => time_spent_logged_in
                                [10] => storage_used
                            )

                        [connection:protected] => 
                        [primaryKey:protected] => id
                        [keyType:protected] => int
                        [perPage:protected] => 15
                        [incrementing] => 1
                        [timestamps] => 1
                        [attributes:protected] => Array
                            (
                                [id] => 3
                                [company_name] => Joe Engineering LTD.
                                [user_first_name] => Joe
                                [user_email] => Joe@gmail.com
                                [plan_name] => Freelance
                                [total_users] => 36
                                [monthly_payment_amount] => 500
                                [term_ending] => 2016-08-08 00:00:00
                                [sign_up_date] => 2015-08-08 00:00:00
                                [receive_special_offers_emails] => Y
                                [time_spent_logged_in] => 50
                                [storage_used] => 500
                                [created_at] => 2016-07-15 06:35:39
                                [updated_at] => 2016-07-15 06:35:39
                            )

                        [original:protected] => Array
                            (
                                [id] => 3
                                [company_name] => Joe Engineering LTD.
                                [user_first_name] => Joe
                                [user_email] => Joe@gmail.com
                                [plan_name] => Freelance
                                [total_users] => 36
                                [monthly_payment_amount] => 500
                                [term_ending] => 2016-08-08 00:00:00
                                [sign_up_date] => 2015-08-08 00:00:00
                                [receive_special_offers_emails] => Y
                                [time_spent_logged_in] => 50
                                [storage_used] => 500
                                [created_at] => 2016-07-15 06:35:39
                                [updated_at] => 2016-07-15 06:35:39
                            )

                        [relations:protected] => Array
                            (
                            )

                        [hidden:protected] => Array
                            (
                            )

                        [visible:protected] => Array
                            (
                            )

                        [appends:protected] => Array
                            (
                            )

                        [guarded:protected] => Array
                            (
                                [0] => *
                            )

                        [dates:protected] => Array
                            (
                            )

                        [dateFormat:protected] => 
                        [casts:protected] => Array
                            (
                            )

                        [touches:protected] => Array
                            (
                            )

                        [observables:protected] => Array
                            (
                            )

                        [with:protected] => Array
                            (
                            )

                        [morphClass:protected] => 
                        [exists] => 1
                        [wasRecentlyCreated] => 
                    )

                [3] => DayJibe\DAL\Company\Models\CompanyModel Object
                    (
                        [table:protected] => companies
                        [fillable:protected] => Array
                            (
                                [0] => company_name
                                [1] => user_first_name
                                [2] => user_email
                                [3] => plan_name
                                [4] => total_users
                                [5] => monthly_payment_amount
                                [6] => term_ending
                                [7] => sign_up_date
                                [8] => receive_special_offers_emails
                                [9] => time_spent_logged_in
                                [10] => storage_used
                            )

                        [connection:protected] => 
                        [primaryKey:protected] => id
                        [keyType:protected] => int
                        [perPage:protected] => 15
                        [incrementing] => 1
                        [timestamps] => 1
                        [attributes:protected] => Array
                            (
                                [id] => 4
                                [company_name] => Michal Engineering LTD.
                                [user_first_name] => Michal
                                [user_email] => Michal@gmail.com
                                [plan_name] => Basic
                                [total_users] => 45
                                [monthly_payment_amount] => 400
                                [term_ending] => 2016-09-10 00:00:00
                                [sign_up_date] => 2016-01-05 00:00:00
                                [receive_special_offers_emails] => N
                                [time_spent_logged_in] => 40
                                [storage_used] => 150
                                [created_at] => 2016-07-15 06:36:57
                                [updated_at] => 2016-07-15 06:36:57
                            )

                        [original:protected] => Array
                            (
                                [id] => 4
                                [company_name] => Michal Engineering LTD.
                                [user_first_name] => Michal
                                [user_email] => Michal@gmail.com
                                [plan_name] => Basic
                                [total_users] => 45
                                [monthly_payment_amount] => 400
                                [term_ending] => 2016-09-10 00:00:00
                                [sign_up_date] => 2016-01-05 00:00:00
                                [receive_special_offers_emails] => N
                                [time_spent_logged_in] => 40
                                [storage_used] => 150
                                [created_at] => 2016-07-15 06:36:57
                                [updated_at] => 2016-07-15 06:36:57
                            )

                        [relations:protected] => Array
                            (
                            )

                        [hidden:protected] => Array
                            (
                            )

                        [visible:protected] => Array
                            (
                            )

                        [appends:protected] => Array
                            (
                            )

                        [guarded:protected] => Array
                            (
                                [0] => *
                            )

                        [dates:protected] => Array
                            (
                            )

                        [dateFormat:protected] => 
                        [casts:protected] => Array
                            (
                            )

                        [touches:protected] => Array
                            (
                            )

                        [observables:protected] => Array
                            (
                            )

                        [with:protected] => Array
                            (
                            )

                        [morphClass:protected] => 
                        [exists] => 1
                        [wasRecentlyCreated] => 
                    )

                [4] => DayJibe\DAL\Company\Models\CompanyModel Object
                    (
                        [table:protected] => companies
                        [fillable:protected] => Array
                            (
                                [0] => company_name
                                [1] => user_first_name
                                [2] => user_email
                                [3] => plan_name
                                [4] => total_users
                                [5] => monthly_payment_amount
                                [6] => term_ending
                                [7] => sign_up_date
                                [8] => receive_special_offers_emails
                                [9] => time_spent_logged_in
                                [10] => storage_used
                            )

                        [connection:protected] => 
                        [primaryKey:protected] => id
                        [keyType:protected] => int
                        [perPage:protected] => 15
                        [incrementing] => 1
                        [timestamps] => 1
                        [attributes:protected] => Array
                            (
                                [id] => 5
                                [company_name] => Michal Engineering LTD.
                                [user_first_name] => Michal
                                [user_email] => Michal@gmail.com
                                [plan_name] => Basic
                                [total_users] => 45
                                [monthly_payment_amount] => 400
                                [term_ending] => 0000-00-00 00:00:00
                                [sign_up_date] => 0000-00-00 00:00:00
                                [receive_special_offers_emails] => N
                                [time_spent_logged_in] => 40
                                [storage_used] => 150
                                [created_at] => 2016-07-15 07:58:36
                                [updated_at] => 2016-07-15 07:58:36
                            )

                        [original:protected] => Array
                            (
                                [id] => 5
                                [company_name] => Michal Engineering LTD.
                                [user_first_name] => Michal
                                [user_email] => Michal@gmail.com
                                [plan_name] => Basic
                                [total_users] => 45
                                [monthly_payment_amount] => 400
                                [term_ending] => 0000-00-00 00:00:00
                                [sign_up_date] => 0000-00-00 00:00:00
                                [receive_special_offers_emails] => N
                                [time_spent_logged_in] => 40
                                [storage_used] => 150
                                [created_at] => 2016-07-15 07:58:36
                                [updated_at] => 2016-07-15 07:58:36
                            )

                        [relations:protected] => Array
                            (
                            )

                        [hidden:protected] => Array
                            (
                            )

                        [visible:protected] => Array
                            (
                            )

                        [appends:protected] => Array
                            (
                            )

                        [guarded:protected] => Array
                            (
                                [0] => *
                            )

                        [dates:protected] => Array
                            (
                            )

                        [dateFormat:protected] => 
                        [casts:protected] => Array
                            (
                            )

                        [touches:protected] => Array
                            (
                            )

                        [observables:protected] => Array
                            (
                            )

                        [with:protected] => Array
                            (
                            )

                        [morphClass:protected] => 
                        [exists] => 1
                        [wasRecentlyCreated] => 
                    )

            )

    )

[perPage:protected] => 5
[currentPage:protected] => 1
[path:protected] => http://dayjibe.localhost.com/api/v1.0/company
[query:protected] => Array
    (
    )

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

1 个答案:

答案 0 :(得分:0)

我发现了这个: $ users = CompanyModel :: paginate(5); 响应:: JSON($用户);

如果我们这样做,那么在JSON响应中它会自动添加诸如per_page,current_page,from等参数。

所以是的,我们需要做Response :: json,然后从中获取所需的Paramus。

谢谢你们:)