lichris/blitz

:description

dev-master 2018-07-05 12:00 UTC

This package is not auto-updated.

Last update: 2024-09-20 22:23:06 UTC


README

Latest Version on Packagist Total Downloads Build Status StyleCI

这里应该放置您的描述。请查看contributing.md以查看待办事项列表。

安装

通过 Composer

$ composer require lichris/blitz

用法

模型(管理从数据库获取的记录)

<?php

namespace Api\V1\Models;

use Lichris\Blitz\Models\Model;

class User extends Model
{
    // 모델 __construct(dbRecord) 시 존재하지 않는
    // 열 (column) 을 자동적으로 제외합니다
    // 예) new User(['asdf' => 1, 'id' => 1]) -> User(['id' => 1])
    protected $filter = [
        'id',
        'uuid',
        'email',
        'password',
        'name',
        'nickname',
        'phone_number',
    ];
    
    // toArray() __toString() toJson() 시 출력되지 않아야할 필드들
    protected $hidden = [
        'id',
        'email',
        'password',
    ];

    // 관계 모델
    // __construct() 시 $filter 와 array_merge 되어 삽입
    protected $relations = [
        'alert_disable',
    ];
}

Blitz(与数据库直接通信)

<?php 

namespace Api\V1\Blitz;

use Api\V1\Models\User;
use Lichris\Blitz\Blitz;

/**
 * Class UserRepository.
 */
class UserBlitz extends Blitz
{
    protected $modelClass = User::class;

    protected $table = 'users';

    protected $name = '사용자';

    protected $single = 'user';

    protected $softDelete = true;

    protected $relations = [
        'alert_disable',
    ];

    public function alertDisable()
    {
        // Query Builder 가 지원하는 함수 체이닝 해서 사용 가능합니다
        return $this->hasOne(AlertDisableRepository::class, 'alert_disables', 'user_id')
            ->orderBy('id', 'desc');
    }
}

控制器(实际使用示例)

<?php

namespace Api\V1\Controllers;

use Api\V1\Blitz\UserBlitz;

class UserController extends BaseController
{
    public function test()
    {
        $uBlitz = new UserBlitz();

        return view('test', [
            'dump' => [
                $uBlitz->whereIn('id', [1, 2, 3, 4])->first(),
                $uBlitz->whereIn('id', [1, 2, 3, 4])->get(),
                $uBlitz->find(1),
                $uBlitz->find(1)->with(null),
            ],
        ]);
    }
}

变更日志

有关最近更改的更多信息,请参阅变更日志

测试

测试尚未支持(进行中)

贡献

请参阅contributing.md以获取详细信息及待办事项列表。

安全

如果您发现任何与安全相关的问题,请通过电子邮件1541.hsl@gmail.com联系,而不是使用问题跟踪器。

鸣谢

许可证

MIT。请参阅许可证文件以获取更多信息。