feodorpranju / api-orm
此包最新版本(v1.0.2)没有提供许可证信息。
字段和模型合约及基本转换器
v1.0.2
2023-11-20 20:12 UTC
Requires
- php: ^8.1
- brick/phonenumber: ^0.5.0
- egulias/email-validator: ^4.0
- guzzlehttp/guzzle: ^6.2.1|^7.0.1
- illuminate/collections: ^10.4
- illuminate/container: ^10.22
- illuminate/contracts: ^10.4
- illuminate/http: ^10.22
- illuminate/log: ^10.22
- illuminate/support: ^10.22
- nesbot/carbon: ^2.66
- psr/log: ^1.1.4 || ^2.0 || ^3.0
Requires (Dev)
- phpunit/phpunit: ^10.0
- symfony/var-dumper: ^6.2
This package is auto-updated.
Last update: 2024-09-20 22:14:49 UTC
README
将 git@github.com:feodorpranju/api-orm.git
添加到你的 composer.json
仓库列表中,类型为 github
。通过运行 composer require feodorpranju/api-orm
进行安装。
使用方法
-
模型创建
<?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), ]); } }
设置所需方法,例如 get(),fields(),find(),count()...
-
模型初始化
$task = Task::get(1); $task = Task::select()->first(); $task = Task::where('id', 1)->first(); $task = new Task(['id' => 1]); $task = Task::make(['id' => 1]);
-
模型字段使用
$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' ]);
-
选择模型
# 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();