我有一個對象,所以我想知道怎樣才能從object.Object例如數據低於怎樣才能從對象數據在PHP
return $response= PowerConsumption::groupBY('device_id')
->selectRaw('round(sum(unit),4) as yAxis,device_id')
->where('created_at',Carbon::now())->paginate(1);
給出所以這雄辯查詢創建給定的數據,但我需要current_page,請不要更改我的查詢。只有幫助我找出此響應的current_page值。
{
total: 2,
per_page: 1,
current_page: 1,
last_page: 2,
next_page_url: "http://localhost:8000/graph/monthly/user_id/2?page=2",
prev_page_url: null,
from: 1,
to: 1,
data: [
{
yAxis: 222.8572,
device_id: 1
}
]
}
該數據存儲在$ response變量中,我只需要current_page和last_page,我該如何獲得。 我想要這個樣
$response['current_page']; //it's return null
$response->current_page; //it's return error like
Undefined property: Illuminate\Pagination\LengthAwarePaginator::$current_page
請幫我在獲取數據
您的'$ response'不是您認爲的那樣。它是['LengthAwarePaginator'](https://laravel.com/api/5.0/Illuminate/Pagination/LengthAwarePaginator.html)。也許它包含一個響應對象? – Chris
你能顯示'var_dump($ response);'? – RomanPerekhrest
$ resonse-> current_page; <====你缺少字符[p] –