avertys/lighter
Composer 安装命令:
composer require avertys/lighter
包简介
Make your requests lighter
README 文档
README
Lighter is a package htaht help you improve performances of your request. You can specify which data you want to keep in your model or let the client request what he wants.
Installation
In order to install Lighter, just use compose:
composer require "avertys/lighter"
How to use Lighter
On model
To use lighter on your model you have to add Avertys\Lighter\LighterTrait to your model
class User extends Model { use LighterTrait; protected $appends = ['fullname']; }
Then, you just have to write the followinf code. In this example, accessors are not calculated.
$user = User::find(1); return response()->json( $user->lighter()->keep(['name', 'address']); , 200); /* { "name" : "Steve", "age" : "28" } */
You also can use lighter on collection with the helper.
$users = User::all(); return response()->json( lighter($users)->keep(['name', 'address']); , 200); /* { "name" : "Steve", "age" : "28" }, { "name" : "John", "age" : "35" }, */
Helper can be use on model
$user = User::find(1); return response()->json( lighter($user)->keep(['name', 'address']); , 200); /* { "name" : "Steve", "age" : "28" }, { "name" : "John", "age" : "35" }, */
Using the request : Let your client request what he needs.
In the params, add as _keep parameter http://localhost/users?_keep["name"] .
$user = User::find(1); return response()->json( lighter($user)->keep(); , 200); /* { "name" : "Steve", "age" : "28" }, { "name" : "John", "age" : "35" }, */
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-12-14