Giter VIP home page Giter VIP logo

blitz's Introduction

Blitz

Latest Version on Packagist Total Downloads Build Status StyleCI

This is where your description should go. Take a look at contributing.md to see a to do list.

Installation

Via Composer

$ composer require lichris/blitz

Usage

모델 (DB 에서 받아온 레코드를 관리)

<?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',
    ];
}

블리츠 (DB 와 직접 통신)

<?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),
            ],
        ]);
    }
}

Change log

Please see the changelog for more information on what has changed recently.

Testing

Testing is not yet supported (in progress)

Contributing

Please see contributing.md for details and a todolist.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

MIT. Please see the license file for more information.

blitz's People

Contributors

heeseunglee avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.