定制 feodorpranju/api-orm 二次开发

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

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

feodorpranju/api-orm

最新稳定版本:v1.0.2

Composer 安装命令:

composer require feodorpranju/api-orm

包简介

Field and Model contracts and basic converters

README 文档

README

Add git@github.com:feodorpranju/api-orm.git to your repository list in composer.json with type github. Install running composer require feodorpranju/api-orm.

Usage

  • Model creation

    <?php
    
    use Feodorpranju\ApiOrm\Models\AbstractModel;
    use \Illuminate\Support\Collection;
    use \Feodorpranju\ApiOrm\Models\Fields\Settings as FieldSettings;
    use \Feodorpranju\ApiOrm\Enumerations\FieldType;
    
    class Task extends AbstractModel
    {
        /**
        * @inheritdoc 
        */
        public static function fields() : Collection
        {
            return collect([
                new FieldSettings('id', FieldType::Int, false, true),
                new FieldSettings('title', FieldType::String),
                new FieldSettings('name', FieldType::String),
                new FieldSettings('date', FieldType::Datetime),
            ]);
        }
    }

    Set required methods e.g. get(), fields(), find(), count()...

  • Model initialization

    $task = Task::get(1);
    $task = Task::select()->first();
    $task = Task::where('id', 1)->first();
    $task = new Task(['id' => 1]);
    $task = Task::make(['id' => 1]);
  • Model field usage

    $task = Task::make([
        'id' => 1,
        'title' => 'Lorem ipsum'
    ]);
    
    # Field get
    echo $task->id;
    echo $task['ID'];
    
    # All fields
    $fields = $task->only();
    $fields = $task->except();
    
    # Needed fields
    $fields = $task->only(['id']);
    $fields = $task->except(['id']);
    
    # Field set
    $task->id = 2;
    $task['id'] = 2;
    $task->put([
        'id' => 2,
        'name' => 'dolor'
    ]);
  • Select models

    # Basic
    $tasks = Task::select()->all();
    $tasks = Task::select()->forPage(1, 10)->get();
    
    # With conditions
    $tasks = Task::select(['id', 'title'])->all();
    $tasks = Task::select()->where('id', 1)->all();
    $tasks = Task::where('id', '=', 1)->all();
    $tasks = Task::where('id', '!=', 1)->all();
    $tasks = Task::where('active')->all();
    $tasks = Task::where([
        'id' => 'Lorem',
        'title' => ['!=', 'ipsum'],
        ['name', 'dolor'],
        ['date', '<=', date('c')],
    ])->all();

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2023-09-01