承接 avertys/lighter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-14

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固