无法在 laravel 中找到用于分页的链接
unable to find links in laravel for pagination
我收到了一个 json 回复,就像这张便条 我正在使用 GuzzleHttp 来调用我的 API
$response = $response->getBody()->getContents();
$output = (json_decode($response));
dd(output)
{#232 ▼
+"current_page": 1
+"data": array:2 [▼
0 => {#230 ▼
+"id": 1
+"test_col": "Test one"
}
1 => {#237 ▼
+"id": 3
+"test_col": "Test three"
}
]
+"first_page_url": "http://api/api/test?page=1"
+"from": 1
+"last_page": 8
+"last_page_url": "http://api/api/test?page=8"
+"next_page_url": "http://api/api/test?page=2"
+"path": "http://api/api/test"
+"per_page": 2
+"prev_page_url": null
+"to": 2
+"total": 15
}
现在当我去我的前端做这个
{{$outputs->links()}}
获取分页链接显示错误
ErrorException (E_ERROR) Call to undefined method stdClass::links()
我API这边正在做这个
$results = DB::table('test_table')->paginate(2);
return ($results);
来自响应($output)的对象不能有任何方法。响应已经有链接(first_page_url、last_page_url、next_page_url)。如果您需要 HTML 呈现链接,那么您可以尝试创建 LengthAwarePaginator
的实例
$pagination = new LengthAwarePaginator($outputs->data, $outputs->total, $outputs->per_page, $outputs->current_page);
echo $pagination->links();
(未测试)
我收到了一个 json 回复,就像这张便条 我正在使用 GuzzleHttp 来调用我的 API
$response = $response->getBody()->getContents();
$output = (json_decode($response));
dd(output)
{#232 ▼
+"current_page": 1
+"data": array:2 [▼
0 => {#230 ▼
+"id": 1
+"test_col": "Test one"
}
1 => {#237 ▼
+"id": 3
+"test_col": "Test three"
}
]
+"first_page_url": "http://api/api/test?page=1"
+"from": 1
+"last_page": 8
+"last_page_url": "http://api/api/test?page=8"
+"next_page_url": "http://api/api/test?page=2"
+"path": "http://api/api/test"
+"per_page": 2
+"prev_page_url": null
+"to": 2
+"total": 15
}
现在当我去我的前端做这个
{{$outputs->links()}}
获取分页链接显示错误
ErrorException (E_ERROR) Call to undefined method stdClass::links()
我API这边正在做这个
$results = DB::table('test_table')->paginate(2);
return ($results);
来自响应($output)的对象不能有任何方法。响应已经有链接(first_page_url、last_page_url、next_page_url)。如果您需要 HTML 呈现链接,那么您可以尝试创建 LengthAwarePaginator
的实例$pagination = new LengthAwarePaginator($outputs->data, $outputs->total, $outputs->per_page, $outputs->current_page);
echo $pagination->links();
(未测试)