jlozanomaltos/json-reducer

一个使用模型、集合、数组进行数组大小减少器(用于JSON输出目的)

v1.0.9 2017-01-12 09:43 UTC

This package is not auto-updated.

Last update: 2024-09-23 15:13:17 UTC


README

这是什么?

一个数组大小减少器(用于JSON输出目的),使用Laravel/Lumen的模型、集合和数组

基本上是以下实现的实现: 较小的序列化数据

输入示例(Eloquent模型数组可视化)

{
 "data": [
		{
			"id": 1,
			"name": "Jesús Emanuel",
			"lastname": "Lozano Maltos"
		},
		{
			"id": 2,
			"name": "Gilberto",
			"lastname": "Reyes Barrera"
		}
  ]
}

输出示例(数组可视化)

{
 "data": {
		{
			"id":[1, 2],
			"name": ["Jesús Emanuel", "Gilberto"],
			"lastname": ["Lozano Maltos", "Reyes Barrera"]
		}
  }
}

安装

使用composer安装包

composer require jlozanomaltos/json-reducer

然后只需要要求该类(您需要的部分)

use JLozanoMaltos\JsonReducer\JsonReducer;

示例用法(Laravel)

public function index()
{
	$users = User::all();
	return response()->json(JsonReducer::reduce($users));
}