2016-07-18 26 views
0

我做這樣的事情Laralvel 5.2分頁不會返回並PARAMS

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

當我打印這一點,就會打印出「照亮\分頁\ LengthAwarePaginator對象」,它會返回PARAMS如總, 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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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] => [email protected] 
           [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 

+0

請發佈你有什麼'print_r($ users);'。 – Manwal

+5

聽起來像是一個可以通過閱讀手冊回答的問題 – RiggsFolly

+0

請快速瀏覽文檔[這裏](https://laravel.com/docs/5.2/pagination)。它在大多數情況下會立即起作用 – iSS

回答

0

我發現這一點: $用戶= CompanyModel :: PAGINATE(5); Response :: json($ users);

如果我們這樣做,那麼在JSON響應它會自動添加參數,如per_page,CURRENT_PAGE,從以等

所以,是的,我們需要做響應:: JSON,然後需要獲得來自帕拉姆斯它。

謝謝你們:) :)