我有一个关于的JSON响应
{"total":3594,"per_page":20,"current_page":18,"last_page":180,"next_page_url":"http:\/\/localhost:7777\/youtube\/public\/service\/category\/user_id\/education?page=19","prev_page_url":"http:\/\/localhost:7777\/app\/public\/test?page=17","from":341,"to":360我需要删除它,并只显示选定的结果数据。
发布于 2016-09-17 10:08:49
如果您想要集合,可以使用:
$paginated = Model::paginate(10);
$collection = $paginated->getCollection();发布于 2018-03-06 13:19:31
假设您的模型名为Product,那么您只能获得产品的数据(没有分页数据),如下所示:
// Add conditions to the query according to your needs
$data = Product::paginate(10);
// More info about toArray() method, see: vendor\laravel\framework\src\Illuminate\Pagination\LengthAwarePaginator.php file
$result = $data->toArray();
// Now, what you need is the $result["data"] element
$products = $result["data"];$result数组是一个具有以下键的关联数组:
current_page
data
first_page_url
from
last_page
last_page_url
next_page_url
path
per_page
prev_page_url
to
total
您可以根据需要使用或取消$result数组中的任何元素。
https://stackoverflow.com/questions/39545397
复制相似问题