定制 yonyon/eloquent-schema-query 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

yonyon/eloquent-schema-query

Composer 安装命令:

composer require yonyon/eloquent-schema-query

包简介

EloquentSchemaQuery is a library that extracts only required items from Eloquent.

README 文档

README

EloquentSchemaQuery is a library that extracts only required items from Eloquent. Describe items to be acquired using schema.

Install

composer require yonyon/eloquent-schema-query::dev-master

Use Laravel

After updating composer, add the service provider to the providers array in config/app.php

'providers' => [
    // Other service providers...

    yonyon\EloquentSchemaQuery\Provider\EloquentSchemaQueryServiceProvider::class,
],

Also, add the facade to the aliases array in your app configuration file:

'EloquentSchemaQuery' => \yonyon\EloquentSchemaQuery\Facades\EloquentSchemaQuery::class,

Example

$user = User::find(1);

$schema = new Schema([
  'id',
  'name',
  'todos' => new Schema([
    'name'
  ])
]);

$result = EloquentSchemaQuery::get($user, $schema);

When you want to change the item name

The second argument to schema is an alias for the item name.

$schema = new Schema([
  'id',
  'name',
  'todos' => new Schema([
    'name'
  ], 'todo_list') 
]);

FunctionSchema

FunctionSchema is used when you want to obtain the result of executing eloquent's query, such as the number of todo.

$schema = new Schema([
  'id',
  'name',
  'todo_count' => new FunctionSchema(function($user) {
    return $user->todos->count();
  })
]);

If the query result is Collection or Model, you have to define schema as the second argument.

$schema = new Schema([
  'id',
  'name',
  'todo_count' => new FunctionSchema(
    function($user) {
      return $user->todos;
    },
    new Schema([
      'name'
    ]
  )
]);

统计信息

  • 总下载量: 59
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-08-16

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固