我有一个带有元信息的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
我需要删除并仅显示选定的结果数据..
如果你想要这个系列你可以得到它:
$paginated = Model::paginate(10);
$collection = $paginated->getCollection();
假设您的模型名称是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
阵列中的任何元素。