├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── README.md ├── composer.json ├── composer.lock ├── gula.png ├── phpunit.xml ├── src ├── Console │ ├── AutoGenerateG5WriteModels.php │ ├── GenerateG5CustomModel.php │ ├── GenerateG5WriteModel.php │ └── stubs │ │ ├── G5CustomModel.php.stub │ │ └── G5WriteModel.php.stub ├── G5Model.php ├── G5ModelFactory.php ├── GuLaServiceProvider.php ├── Models │ ├── Gnu │ │ ├── G5Auth.php │ │ ├── G5Autosave.php │ │ ├── G5Board.php │ │ ├── G5BoardFile.php │ │ ├── G5BoardGood.php │ │ ├── G5BoardNew.php │ │ ├── G5CertHistory.php │ │ ├── G5Config.php │ │ ├── G5Content.php │ │ ├── G5Faq.php │ │ ├── G5FaqMaster.php │ │ ├── G5Group.php │ │ ├── G5GroupMember.php │ │ ├── G5Login.php │ │ ├── G5Mail.php │ │ ├── G5Member.php │ │ ├── G5MemberSocialProfiles.php │ │ ├── G5Memo.php │ │ ├── G5Menu.php │ │ ├── G5NewWin.php │ │ ├── G5Point.php │ │ ├── G5Poll.php │ │ ├── G5PollEtc.php │ │ ├── G5Popular.php │ │ ├── G5QaConfig.php │ │ ├── G5QaContent.php │ │ ├── G5Scrap.php │ │ ├── G5Uniqid.php │ │ ├── G5Visit.php │ │ └── G5VisitSum.php │ └── Young │ │ ├── G5ShopBanner.php │ │ ├── G5ShopCart.php │ │ ├── G5ShopCategory.php │ │ ├── G5ShopCoupon.php │ │ ├── G5ShopCouponLog.php │ │ ├── G5ShopCouponZone.php │ │ ├── G5ShopDefault.php │ │ ├── G5ShopEvent.php │ │ ├── G5ShopEventItem.php │ │ ├── G5ShopInicisLog.php │ │ ├── G5ShopItem.php │ │ ├── G5ShopItemOption.php │ │ ├── G5ShopItemQa.php │ │ ├── G5ShopItemRelation.php │ │ ├── G5ShopItemStocksms.php │ │ ├── G5ShopItemUse.php │ │ ├── G5ShopOrder.php │ │ ├── G5ShopOrderAddress.php │ │ ├── G5ShopOrderData.php │ │ ├── G5ShopOrderDelete.php │ │ ├── G5ShopOrderPostLog.php │ │ ├── G5ShopPersonalpay.php │ │ ├── G5ShopSendcost.php │ │ └── G5ShopWish.php ├── Traits │ ├── BelongToG5Board.php │ ├── BelongToG5Member.php │ ├── BelongToG5ShopItem.php │ └── BelongToG5ShopOrder.php └── config │ └── gula.php └── tests ├── Feature ├── AutoGenerateG5WriteModelsTest.php ├── G5ModelTest.php ├── GenerateG5CustomModelTest.php └── GenerateG5WriteModelTest.php ├── TestCase.php └── Unit ├── G5MemberWriteTableTest.php ├── G5ModelFactoryTest.php └── G5RelationTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | .env -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # v1.3.2 2 | - env 파일을 찾지 못하는 버그 수정 3 | 4 | # v1.3.1 5 | - G5BoardFile가 use 되지 않은 버그 수정 6 | 7 | # v1.3.0 8 | - AI가 적용된 테이블의 경우 primary key을 설정 9 | - G5Write의 생성 stub에 files 메소드를 추가 10 | - G5BoardFiles 모델과 릴레이션 11 | 12 | # v1.2.1 13 | - G5Write에서 get relation value가 동작하지 않는 문제 해결 14 | 15 | # v1.2.0 16 | - G5Board에서 생성된 개시판을 가져와 자동으로 모델링을 해주는 명령어 추가 17 | 18 | # v1.1.0 19 | - G5Member primary key를 mb_id로 변경 20 | - G5Write 모델 추가없이 자동 릴레이션 기능 개선 (구라(ㅎ)에서 진짜로) 21 | 22 | # v1.0.0 23 | - 커맨드 `g5model:make {table_name}`과 `g5model:write {board}`과 커맨드 추가 24 | - 커맨드 사용법 추가 25 | 26 | # v0.2.1 27 | - G5Member Model `g5_write`로 시작하는 테이블 G5Write 자동 Relationship 28 | 29 | # v0.2.0 30 | - Laravel relation 추가 31 | - Relation 사용방법 추가 32 | 33 | # v0.1.0 34 | - G5ModelFactory class 추가 35 | - G5ModelFactory 사용방법 추가 36 | 37 | # v0.0.2 38 | - 커스텀 모델 생성 방법 추가 39 | - timestamp 관리 위치 변경 40 | 41 | # v0.0.1 42 | - GuLa 패키지 등록 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | All licenses in this repository are copyrighted by their respective authors. 2 | 3 | Everything else is released under CC0. 4 | 5 | ------------------------------------------------------------------------------ 6 | 7 | No Copyright 8 | 9 | The person who associated a work with this deed has dedicated the work to the 10 | public domain by waiving all of his or her rights to the work worldwide under 11 | copyright law, including all related and neighboring rights, 12 | to the extent allowed by law. 13 | 14 | You can copy, modify, distribute and perform the work, even for commercial 15 | purposes, all without asking permission. See Other Information below. 16 | 17 | Other Information: 18 | 19 | * In no way are the patent or trademark rights of any person affected 20 | by CC0, nor are the rights that other persons may have in the work or in 21 | how the work is used, such as publicity or privacy rights. 22 | 23 | * Unless expressly stated otherwise, the person who associated a work with 24 | this deed makes no warranties about the work, and disclaims liability for 25 | all uses of the work, to the fullest extent permitted by applicable law. 26 | 27 | * When using or citing the work, you should not imply endorsement 28 | by the author or the affirmer. 29 | 30 | http://creativecommons.org/publicdomain/zero/1.0/legalcode -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #

![GuLa-logo](./gula.png)

2 |

그누보드로 RESTfull api 개발을 위한 Laravel Models

3 | 4 | ## Installation 5 | 1. 패키지 설치 `composer require silnex/gula` 6 | 2. `.env` 설정 7 | ```env 8 | GULA_DB_HOST=gnuboard.db.host 9 | GULA_DB_PORT=3306 # (default: 3306) 10 | GULA_DB_DATABASE=gnuboard_db 11 | GULA_DB_USERNAME=gnuboard_db_user 12 | GULA_DB_PASSWORD=gnuboard_db_pass 13 | GULA_CHARSET=utf8mb4 # DB 문자셋 (default: utf8mb4) 14 | GULA_COLLATION=utf8mb4_unicode_ci # DB 문자셋 (default: utf8mb4_unicode_ci) 15 | ``` 16 | 17 | ## How to use 18 | 19 | ### Laravel의 Eloquent 모델을 이용해 데이터 접근 20 | ```php 21 | where('mb_id', '=', 'admin')->get(); 26 | 27 | // 영카트 28 | use SilNex\GuLa\Models\Young\G5ShopItem; 29 | $g5ShopItem = new G5ShopItem; 30 | $g5ShopItem->get(); 31 | ``` 32 | 자세한 사용법은 [Laravel Eloquent](https://laravel.kr/docs/eloquent) 문서를 참고 33 | 34 | ### Relationships 35 | Laravel의 모델의 Relation을 사용해 다른 테이블의 내용을 쉽게 가져올 수 있습니다. 36 | ```php 37 | where('mb_id', '=', 'admin')->first(); 42 | $admin->g5Points()->get(); 43 | ``` 44 | 45 | ### G5ModelFactory 46 | 미리 생성된 Model이 없는 경우나, 다른 DB에서 가져올 경우 `G5ModelFactory`를 통해 Model 인스턴스를 생성할 수 있습니다. 47 | ```php 48 | get(); 56 | ``` 57 | 58 | 혹은 이를 응용해 다음과 같은 방법도 가능합니다. 59 | ```php 60 | get(); 74 | } 75 | ``` 76 | 77 | ### 자동 릴레이션 78 | 그누보드에선 새로운 게시판을 만들때 마다 `g5_write_`으로 시작하는 테이블이 생성됩니다. 79 | GuLa에선 이를 자동으로 릴레이션 해줍니다. 80 | ```테이블 이름이 소문자, _, 숫자인 경우에만 자동 인식이 가능합니다.``` 81 | ```php 82 | where('mb_id', '=', 'admin')->first(); 89 | $admin->g5WriteFree()->first(); // g5_write_free의 mb_id가 admin인 게시글을 가져옵니다. 90 | 91 | // 여러 테이블에서 가져올 수 있습니다. 92 | $admin->with('g5WriteFree', 'g5WriteNotice', 'g5WriteQa')->get(); 93 | ``` 94 | 95 | ### 커스텀 모델 (테이블) 96 | 커스텀 모델을 직접 만들지 않고 커맨드로 생성 할 수 있습니다. 97 | #### 모델 생성 98 | 커맨드 `php artisan g5model:write {table_name}`를 입력하면 `app/G5Models`에 모델이 생성 됩니다. 99 | ##### 예시 100 | ```bash 101 | php artisan g5model:write my_g5_custom_table 102 | ``` 103 | ```php 104 | /** app/G5Models/MyG5CustomTable.php */ 105 | 106 | hasMany(G5WriteFree::class, 'wr_parent', 'wr_id')->where('wr_is_comment', '=', '1');; 152 | } 153 | 154 | /** 155 | * 댓글이라면, 게시글을 보여줌 156 | */ 157 | public function parent() 158 | { 159 | if ($this->wr_is_comment) { 160 | return $this->belongsTo(G5WriteFree::class, 'wr_id', 'wr_parent')->where('wr_is_comment', '=', '0');; 161 | } else { 162 | throw new \Exception("해당 글은 댓글이 아닙니다."); 163 | } 164 | } 165 | 166 | /** 167 | * 게시판에 첨부된 파일을 가져옴 168 | */ 169 | public function files() 170 | { 171 | return $this->hasMany(G5BoardFile::class, 'wr_id', 'wr_id')->where('bo_table', $this->bo_table); 172 | } 173 | } 174 | 175 | // Using 176 | $g5WriteFree = new G5WriteFree; 177 | $g5WriteFree->comments(); 178 | $g5WriteFree->first()->files(); 179 | ``` 180 | 181 | #### g5_board테이블에 있는 모든 게시판 생성 182 | `php artisan g5model:write-all` 명령어를 통해 자동으로 그누보드의 게시판 모델을 생성해 줄수 있습니다. 183 | 184 | ### Todo 185 | - [x] 그누보드 모델 추가 186 | - [x] Mass Assignment 추가 187 | - [x] 그누보드 DB connection 분리 188 | - [x] 로고제작 (임시용) 189 | - [x] 로고제작 (정식용) 190 | - [x] 모델 인스턴스 팩토리 추가 191 | - [x] 모델별 릴레이션 추가 192 | - [x] g5_write 테이블 자동 릴레이션 193 | - [x] 커스텀 모델 artisan:make 커맨드 추가 194 | - [x] DB에 있는 g5_write_ 테이블 모델 일괄 생성 커맨드 추가 195 | - [x] 테이블별 primaryKey 설정 196 | - [x] G5Write Model과 G5BoardFile의 연결 -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "silnex/gula", 3 | "description": "Laravel for Gnuboard5", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "silnex", 8 | "email": "silnex@silnex.kr" 9 | } 10 | ], 11 | "require": { 12 | "laravel/framework": "^7.0" 13 | }, 14 | "autoload": { 15 | "psr-4": { 16 | "SilNex\\GuLa\\": "src" 17 | } 18 | }, 19 | "extra": { 20 | "laravel": { 21 | "providers": [ 22 | "SilNex\\GuLa\\GuLaServiceProvider" 23 | ] 24 | } 25 | }, 26 | "autoload-dev": { 27 | "psr-4": { 28 | "SilNex\\GuLa\\Tests\\": "tests", 29 | "App\\": "vendor/orchestra/testbench-core/laravel/app" 30 | } 31 | }, 32 | "require-dev": { 33 | "orchestra/testbench": "^5.0" 34 | } 35 | } -------------------------------------------------------------------------------- /gula.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/silnex/GuLa/b2a8ab1981d67b079c1d0a0e2f26b78fd60d561f/gula.png -------------------------------------------------------------------------------- /phpunit.xml: -------------------------------------------------------------------------------- 1 | 2 | 14 | 15 | 16 | tests 17 | 18 | 19 | 20 | 21 | src/ 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /src/Console/AutoGenerateG5WriteModels.php: -------------------------------------------------------------------------------- 1 | get()->toArray()); 18 | 19 | foreach ($boards as $board) { 20 | $this->info(" {$board} 게시판 모델을 생성합니다."); 21 | $this->call('g5model:write', ['name' => $board]); 22 | } 23 | 24 | $this->info(" 모든 게시판 모델이 생성되었습니다."); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/Console/GenerateG5CustomModel.php: -------------------------------------------------------------------------------- 1 | generateG5WriteModel(); 34 | } 35 | 36 | protected function generateG5WriteModel() 37 | { 38 | $class = $this->getNameInput(); 39 | 40 | $table = Str::snake($class); 41 | 42 | $class = $this->qualifyClass($class); 43 | $path = $this->getPath($class); 44 | 45 | $content = file_get_contents($path); 46 | $content = str_replace('{{ table }}', $table, $content); 47 | 48 | file_put_contents($path, $content); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Console/GenerateG5WriteModel.php: -------------------------------------------------------------------------------- 1 | generateG5WriteModel(); 34 | } 35 | 36 | protected function generateG5WriteModel() 37 | { 38 | $class = $this->getNameInput(); 39 | 40 | $table = Str::snake($class); 41 | 42 | $class = $this->qualifyClass($class); 43 | $path = $this->getPath($class); 44 | 45 | $content = file_get_contents($path); 46 | $content = str_replace('{{ table }}', $table, $content); 47 | $content = str_replace('{{ bo_table }}', explode('g5_write_', $table)[1], $content); 48 | 49 | file_put_contents($path, $content); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/Console/stubs/G5CustomModel.php.stub: -------------------------------------------------------------------------------- 1 | hasMany({{ class }}::class, 'wr_parent', 'wr_id')->where('wr_is_comment', '=', '1'); 58 | } 59 | 60 | /** 61 | * 댓글이라면, 게시글을 보여줌 62 | */ 63 | public function parent() 64 | { 65 | if ($this->wr_is_comment) { 66 | return $this->belongsTo({{ class }}::class, 'wr_id', 'wr_parent')->where('wr_is_comment', '=', '0'); 67 | } else { 68 | throw new \Exception("해당 글은 댓글이 아닙니다."); 69 | } 70 | } 71 | 72 | /** 73 | * 게시판에 첨부된 파일을 가져옴 74 | */ 75 | public function files() 76 | { 77 | return $this->hasMany(G5BoardFile::class, 'wr_id', 'wr_id')->where('bo_table', $this->bo_table); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/G5Model.php: -------------------------------------------------------------------------------- 1 | newConnection = $data[0] ?? $this->newConnection; 13 | $this->newTable = $data[1] ?? $this->newTable; 14 | $this->setConnection($this->newConnection); 15 | $this->setTable($this->newTable); 16 | parent::__construct([]); 17 | } 18 | 19 | public function newInstance($attributes = [], $exists = false) 20 | { 21 | $model = parent::newInstance($attributes, $exists); 22 | $model->setTable($this->table); 23 | 24 | return $model; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/GuLaServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->bootstrapWith([LoadEnvironmentVariables::class]); 16 | 17 | $this->mergeConfigFrom(__DIR__ . '/config/gula.php', 'gula'); 18 | config(['database.connections.gula' => config('gula')]); 19 | } 20 | 21 | public function boot() 22 | { 23 | if ($this->app->runningInConsole()) { 24 | $this->publishes([ 25 | __DIR__ . '/config/gula.php' => config_path('gula.php'), 26 | ], 'config'); 27 | } 28 | 29 | $this->commands([ 30 | GenerateG5WriteModel::class, 31 | GenerateG5CustomModel::class, 32 | AutoGenerateG5WriteModels::class, 33 | ]); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5Auth.php: -------------------------------------------------------------------------------- 1 | hasMany(G5BoardFile::class, 'bo_table', 'bo_table'); 65 | } 66 | 67 | public function g5BoardNew() 68 | { 69 | return $this->hasMany(G5BoardNew::class, 'bo_table', 'bo_table'); 70 | } 71 | 72 | public function g5BoardGood() 73 | { 74 | return $this->hasMany(G5BoardGood::class, 'bo_table', 'bo_table'); 75 | } 76 | 77 | public function g5Scrap() 78 | { 79 | return $this->hasMany(G5Scrap::class, 'bo_table', 'bo_table'); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5BoardFile.php: -------------------------------------------------------------------------------- 1 | hasMany(G5Board::class, 'gr_id', 'gr_id'); 58 | } 59 | 60 | public function g5Members() 61 | { 62 | return $this->belongsToMany(G5Member::class, 'g5_group_member', 'gr_id', 'mb_id'); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5GroupMember.php: -------------------------------------------------------------------------------- 1 | hasMany(G5Auth::class, 'mb_id', 'mb_id'); 84 | } 85 | 86 | public function g5Boards() 87 | { 88 | return $this->hasMany(G5Board::class, 'bo_admin', 'mb_id');; 89 | } 90 | 91 | public function g5BoardGoods() 92 | { 93 | return $this->hasMany(G5BoardGood::class, 'mb_id', 'mb_id'); 94 | } 95 | 96 | public function g5BoardNews() 97 | { 98 | return $this->hasMany(G5BoardNew::class, 'mb_id', 'mb_id'); 99 | } 100 | 101 | public function g5CertHistorys() 102 | { 103 | return $this->hasMany(G5CertHistory::class, 'mb_id', 'mb_id'); 104 | } 105 | 106 | public function g5Groups() 107 | { 108 | return $this->belongsToMany(G5Group::class, 'g5_group_member', 'mb_id', 'gr_id'); 109 | } 110 | 111 | public function g5Logins() 112 | { 113 | return $this->hasMany(G5Login::class, 'mb_id', 'mb_id'); 114 | } 115 | 116 | public function g5MemoReceivers() 117 | { 118 | return $this->hasMany(G5Memo::class, 'me_recv_mb_id', 'mb_id'); 119 | } 120 | 121 | public function g5MemoSenders() 122 | { 123 | return $this->hasMany(G5Memo::class, 'me_send_mb_id', 'mb_id'); 124 | } 125 | 126 | public function g5Points() 127 | { 128 | return $this->hasMany(G5Point::class, 'mb_id', 'mb_id'); 129 | } 130 | 131 | public function g5PollEtcs() 132 | { 133 | return $this->hasMany(G5PollEtc::class, 'mb_id', 'mb_id'); 134 | } 135 | 136 | public function g5Scraps() 137 | { 138 | return $this->hasMany(G5Scrap::class, 'mb_id', 'mb_id'); 139 | } 140 | 141 | public function g5Autosaves() 142 | { 143 | return $this->hasMany(G5Autosave::class, 'mb_id', 'mb_id'); 144 | } 145 | 146 | public function g5QaContents() 147 | { 148 | return $this->hasMany(G5QaContent::class, 'mb_id', 'mb_id'); 149 | } 150 | 151 | public function g5MemberSocialProfiles() 152 | { 153 | return $this->hasMany(G5MemberSocialProfiles::class, 'mb_id', 'mb_id'); 154 | } 155 | 156 | /** 157 | * Youngcart relation 158 | */ 159 | 160 | public function g5ShopCarts() 161 | { 162 | return $this->hasMany(G5ShopCart::class, 'mb_id', 'mb_id'); 163 | } 164 | 165 | public function g5ShopCategorys() 166 | { 167 | return $this->hasMany(G5ShopCategory::class, 'ca_mb_id', 'mb_id'); 168 | } 169 | 170 | public function g5ShopCoupons() 171 | { 172 | return $this->hasMany(G5ShopCoupon::class, 'mb_id', 'mb_id'); 173 | } 174 | 175 | public function g5ShopCouponLogs() 176 | { 177 | return $this->hasMany(G5ShopCouponLog::class, 'mb_id', 'mb_id'); 178 | } 179 | 180 | public function g5ShopItemUses() 181 | { 182 | return $this->hasMany(G5ShopItemUse::class, 'mb_id', 'mb_id'); 183 | } 184 | 185 | public function g5ShopItemQas() 186 | { 187 | return $this->hasMany(G5ShopItemQa::class, 'mb_id', 'mb_id'); 188 | } 189 | 190 | public function g5ShopOrders() 191 | { 192 | return $this->hasMany(G5ShopOrder::class, 'mb_id', 'mb_id'); 193 | } 194 | 195 | public function g5ShopOrderAddress() 196 | { 197 | return $this->hasMany(G5ShopOrderAddress::class, 'mb_id', 'mb_id'); 198 | } 199 | 200 | public function g5ShopOrderDatas() 201 | { 202 | return $this->hasMany(G5ShopOrderData::class, 'mb_id', 'mb_id'); 203 | } 204 | 205 | public function g5ShopOrderDeletes() 206 | { 207 | return $this->hasMany(G5ShopOrderDelete::class, 'mb_id', 'mb_id'); 208 | } 209 | 210 | public function g5ShopWishs() 211 | { 212 | return $this->hasMany(G5ShopWish::class, 'mb_id', 'mb_id'); 213 | } 214 | 215 | public function g5ShopOrderPostLogs() 216 | { 217 | return $this->hasMany(G5ShopOrderPostLog::class, 'mb_id', 'mb_id'); 218 | } 219 | 220 | public function isG5Write($string) 221 | { 222 | return substr($string, 0, 7) === 'g5Write'; 223 | } 224 | 225 | public function __get($key) 226 | { 227 | if ($this->isG5Write($key)) { 228 | return $this->$key()->get(); 229 | } 230 | parent::__get($key); 231 | } 232 | 233 | public function __call($method, $parameters) 234 | { 235 | if ($this->isG5Write($method)) { 236 | global $silnexGuLaTempTable; 237 | $class = 'App\\G5Models\\' . Str::studly($method); 238 | $silnexGuLaTempTable = Str::snake($method); 239 | 240 | if (!class_exists($class)) { 241 | $anonymousClass = new class extends G5Model 242 | { 243 | use BelongToG5Member; 244 | 245 | protected $guarded = []; 246 | protected $dates = ['wr_datetime']; 247 | 248 | public function __construct() 249 | { 250 | global $silnexGuLaTempTable; 251 | 252 | $this->setTable($silnexGuLaTempTable); 253 | parent::__construct(); 254 | } 255 | 256 | public function comments() 257 | { 258 | return $this->hasMany(self::class, 'wr_parent', 'wr_id')->where('wr_is_comment', '=', '1'); 259 | } 260 | 261 | public function parent() 262 | { 263 | if ($this->wr_is_comment) { 264 | return $this->belongsTo(self::class, 'wr_id', 'wr_parent')->where('wr_is_comment', '=', '0'); 265 | } else { 266 | throw new \Exception("해당 글은 댓글이 아닙니다."); 267 | } 268 | } 269 | 270 | public function files() 271 | { 272 | $bo_table = strtolower(explode('g5Write', self::class)[1]); 273 | return $this->hasMany(G5BoardFile::class, 'wr_id', 'wr_id')->where('bo_table', $bo_table); 274 | } 275 | }; 276 | $class = get_class($anonymousClass); 277 | } 278 | 279 | $this->g5WriteRelationalMethods[$method] = \Closure::bind(function () use ($class) { 280 | return $this->hasMany($class, 'mb_id', 'mb_id'); 281 | }, $this, get_class()); 282 | 283 | if (is_callable($this->g5WriteRelationalMethods[$method])) { 284 | return call_user_func_array($this->g5WriteRelationalMethods[$method], $parameters); 285 | } else { 286 | throw new \Exception("Dynamic method append error"); 287 | } 288 | } 289 | 290 | // parent::__call($method, $parameters); not work 291 | if (in_array($method, ['increment', 'decrement'])) { 292 | return $this->$method(...$parameters); 293 | } 294 | 295 | if ($resolver = (static::$relationResolvers[get_class($this)][$method] ?? null)) { 296 | return $resolver($this); 297 | } 298 | 299 | return $this->forwardCallTo($this->newQuery(), $method, $parameters); 300 | } 301 | } 302 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5MemberSocialProfiles.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5Member::class, 'me_send_mb_id'); 54 | } 55 | 56 | public function g5MemberReceiver() 57 | { 58 | return $this->belongsTo(G5Member::class, 'me_recv_mb_id'); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5Menu.php: -------------------------------------------------------------------------------- 1 | hasMany(G5PollEtc::class, 'po_id', 'po_id'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5PollEtc.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5Poll::class, 'po_id', 'po_id'); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5Popular.php: -------------------------------------------------------------------------------- 1 | hasOne(self::class, 'qa_parent', 'qa_id'); 56 | } 57 | 58 | public function parent() 59 | { 60 | $this->hasOne(self::class, 'qa_id', 'qa_parent'); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Models/Gnu/G5Scrap.php: -------------------------------------------------------------------------------- 1 | hasMany(G5ShopItem::class, 'ca_id', 'ca_id'); 58 | } 59 | 60 | public function g5ShopItemsLevel2() 61 | { 62 | return $this->hasMany(G5ShopItem::class, 'ca_id2', 'ca_id'); 63 | } 64 | 65 | public function g5ShopItemsLevel3() 66 | { 67 | return $this->hasMany(G5ShopItem::class, 'ca_id3', 'ca_id'); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopCoupon.php: -------------------------------------------------------------------------------- 1 | hasMany(G5ShopCouponLog::class, 'cp_id', 'cp_id'); 57 | } 58 | 59 | public function g5ShopCouponZone() 60 | { 61 | return $this->belongsTo(G5ShopCouponZone::class, 'cz_id', 'cz_id'); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopCouponLog.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5ShopCoupon::class, 'cp_id', 'cp_id'); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopCouponZone.php: -------------------------------------------------------------------------------- 1 | hasMany(G5ShopCoupon::class, 'cz_id', 'cz_id'); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopDefault.php: -------------------------------------------------------------------------------- 1 | belongsToMany(G5ShopEvent::class, 'g5_shop_event_item', 'ev_id', 'it_id'); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopEventItem.php: -------------------------------------------------------------------------------- 1 | hasMany(G5ShopCart::class, 'it_id', 'it_id'); 54 | } 55 | 56 | public function g5ShopEvents() 57 | { 58 | return $this->belongsToMany(G5ShopEvent::class, 'g5_shop_event_item', 'it_id', 'ev_id'); 59 | } 60 | 61 | public function g5ShopItemOptions() 62 | { 63 | return $this->hasMany(G5ShopItemOption::class, 'it_id', 'it_id'); 64 | } 65 | 66 | public function g5ShopItemUses() 67 | { 68 | return $this->hasMany(G5ShopItemUse::class, 'it_id', 'it_id'); 69 | } 70 | 71 | public function g5ShopItemQas() 72 | { 73 | return $this->hasMany(G5ShopItemQa::class, 'it_id', 'it_id'); 74 | } 75 | 76 | public function g5ShopItemRelations() 77 | { 78 | return $this->belongsToMany(G5ShopItem::class, 'g5_shop_item_relation', 'it_id', 'it_id2'); 79 | } 80 | 81 | public function g5ShopWishs() 82 | { 83 | return $this->hasMany(G5ShopWish::class, 'it_id', 'it_id'); 84 | } 85 | 86 | public function g5ShopItemStocksms() 87 | { 88 | return $this->hasMany(G5ShopItemStocksms::class, 'it_id', 'it_id'); 89 | } 90 | 91 | public function g5ShopCategoryLevel1() 92 | { 93 | return $this->belongsTo(G5ShopCategory::class, 'ca_id', 'ca_id1'); 94 | } 95 | 96 | public function g5ShopCategoryLevel2() 97 | { 98 | return $this->belongsTo(G5ShopCategory::class, 'ca_id', 'ca_id2'); 99 | } 100 | 101 | public function g5ShopCategoryLevel3() 102 | { 103 | return $this->belongsTo(G5ShopCategory::class, 'ca_id', 'ca_id3'); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopItemOption.php: -------------------------------------------------------------------------------- 1 | hasMany(G5ShopCart::class, 'od_id', 'od_id'); 56 | } 57 | 58 | public function g5ShopCoupon() 59 | { 60 | return $this->hasMany(G5ShopCoupon::class, 'od_id', 'od_id'); 61 | } 62 | 63 | public function g5ShopCouponLog() 64 | { 65 | return $this->hasMany(G5ShopCouponLog::class, 'od_id', 'od_id'); 66 | } 67 | 68 | public function g5ShopOrderData() 69 | { 70 | return $this->hasMany(G5ShopOrderData::class, 'od_id', 'od_id'); 71 | } 72 | 73 | public function g5ShopPersonalpay() 74 | { 75 | return $this->hasMany(G5ShopPersonalpay::class, 'od_id', 'od_id'); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/Models/Young/G5ShopOrderAddress.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5Board::class, 'bo_table', 'bo_table'); 12 | } 13 | } -------------------------------------------------------------------------------- /src/Traits/BelongToG5Member.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5Member::class, $this->g5MemberForeignKey ?? 'mb_id', 'mb_id'); 12 | } 13 | } -------------------------------------------------------------------------------- /src/Traits/BelongToG5ShopItem.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5ShopItem::class, 'it_id', 'it_id'); 12 | } 13 | } -------------------------------------------------------------------------------- /src/Traits/BelongToG5ShopOrder.php: -------------------------------------------------------------------------------- 1 | belongsTo(G5ShopOrder::class, 'od_id', 'od_id'); 12 | } 13 | } -------------------------------------------------------------------------------- /src/config/gula.php: -------------------------------------------------------------------------------- 1 | 'mysql', 5 | 'url' => env('GULA_DATABASE_URL'), 6 | 'host' => env('GULA_DB_HOST', '127.0.0.1'), 7 | 'port' => env('GULA_DB_PORT', '3306'), 8 | 'database' => env('GULA_DB_DATABASE', 'forge'), 9 | 'username' => env('GULA_DB_USERNAME', 'forge'), 10 | 'password' => env('GULA_DB_PASSWORD', ''), 11 | 'unix_socket' => env('GULA_DB_SOCKET', ''), 12 | 'charset' => env('GULA_CHARSET', 'utf8mb4'), 13 | 'collation' => env('GULA_COLLATION', 'utf8mb4_unicode_ci'), 14 | 'prefix' => '', 15 | 'prefix_indexes' => true, 16 | 'strict' => true, 17 | 'engine' => null, 18 | 'options' => extension_loaded('pdo_mysql') ? array_filter([ 19 | PDO::MYSQL_ATTR_SSL_CA => env('GULA_MYSQL_ATTR_SSL_CA'), 20 | ]) : [], 21 | ]; 22 | -------------------------------------------------------------------------------- /tests/Feature/AutoGenerateG5WriteModelsTest.php: -------------------------------------------------------------------------------- 1 | get()->toArray()); 16 | 17 | foreach ($boards as $board) { 18 | $g5MyModelFile = app_path('G5Models/G5Write' . Str::title($board) . '.php'); 19 | if (File::exists($g5MyModelFile)) { 20 | unlink($g5MyModelFile); 21 | } 22 | } 23 | 24 | Artisan::call('g5model:write-all'); 25 | 26 | foreach ($boards as $board) { 27 | $g5MyModelFile = app_path('G5Models/G5Write' . Str::title($board) . '.php'); 28 | $this->assertTrue(File::exists($g5MyModelFile)); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/Feature/G5ModelTest.php: -------------------------------------------------------------------------------- 1 | assertNotSame($g5Member->getConnectionName(), $dummy->getConnectionName()); 15 | } 16 | 17 | public function test_connection_test() 18 | { 19 | $g5Member = new G5Member(); 20 | $g5Member->all(); 21 | 22 | $this->assertTrue(true); 23 | } 24 | } 25 | 26 | class DummyModel extends Model 27 | { 28 | } 29 | -------------------------------------------------------------------------------- /tests/Feature/GenerateG5CustomModelTest.php: -------------------------------------------------------------------------------- 1 | assertFalse(File::exists($g5MyModelFile)); 19 | 20 | Artisan::call('g5model:make g5_my_model'); 21 | 22 | $this->assertTrue(File::exists($g5MyModelFile)); 23 | 24 | $expectedContents = <<assertEquals($expectedContents, file_get_contents($g5MyModelFile)); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/Feature/GenerateG5WriteModelTest.php: -------------------------------------------------------------------------------- 1 | assertFalse(File::exists($g5WriteFreeFile)); 19 | 20 | Artisan::call('g5model:write free'); 21 | 22 | $this->assertTrue(File::exists($g5WriteFreeFile)); 23 | 24 | $expectedContents = <<hasMany(G5WriteFree::class, 'wr_parent', 'wr_id')->where('wr_is_comment', '=', '1'); 82 | } 83 | 84 | /** 85 | * 댓글이라면, 게시글을 보여줌 86 | */ 87 | public function parent() 88 | { 89 | if (\$this->wr_is_comment) { 90 | return \$this->belongsTo(G5WriteFree::class, 'wr_id', 'wr_parent')->where('wr_is_comment', '=', '0'); 91 | } else { 92 | throw new \Exception("해당 글은 댓글이 아닙니다."); 93 | } 94 | } 95 | 96 | /** 97 | * 게시판에 첨부된 파일을 가져옴 98 | */ 99 | public function files() 100 | { 101 | return \$this->hasMany(G5BoardFile::class, 'wr_id', 'wr_id')->where('bo_table', \$this->bo_table); 102 | } 103 | } 104 | 105 | CLASS; 106 | $this->assertEquals($expectedContents, file_get_contents($g5WriteFreeFile)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /tests/TestCase.php: -------------------------------------------------------------------------------- 1 | assertFalse(class_exists($notExistsModel)); 22 | 23 | $g5Member = new G5Member; 24 | $admin = $g5Member->where('mb_id', '=', 'admin')->first(); 25 | $admin->g5WriteFree()->first(); 26 | $this->assertTrue(true); 27 | } 28 | 29 | public function test_g5_write_table_with_relation() 30 | { 31 | $boards = G5Board::select('bo_table')->get()->map(function ($table) { 32 | Artisan::call('g5model:write ' . $table->bo_table); 33 | return 'g5Write' . Str::title($table->bo_table); 34 | })->toArray(); 35 | 36 | $g5Member = new G5Member; 37 | $admin = $g5Member->where('mb_id', '=', 'admin')->first(); 38 | $admin->with($boards)->get(); 39 | $this->assertTrue(true); 40 | } 41 | 42 | public function test_g5_write_table_with_relation_without_model_file() 43 | { 44 | $boards = G5Board::select('bo_table')->get()->map(function ($table) { 45 | $g5WriteFile = app_path('G5Models/G5Write' . Str::title($table->bo_table)); 46 | if (File::exists($g5WriteFile)) { 47 | unlink($g5WriteFile); 48 | } 49 | 50 | return 'g5Write' . Str::title($table->bo_table); 51 | })->toArray(); 52 | 53 | $g5Member = new G5Member; 54 | $admin = $g5Member->where('mb_id', '=', 'admin')->first(); 55 | $admin->with($boards)->get(); 56 | $this->assertTrue(true); 57 | } 58 | 59 | public function test_g5_write_table_relation_value_without_model_file() 60 | { 61 | $boards = G5Board::select('bo_table')->get()->map(function ($table) { 62 | $g5WriteFile = app_path('G5Models/G5Write' . Str::title($table->bo_table)); 63 | if (File::exists($g5WriteFile)) { 64 | unlink($g5WriteFile); 65 | } 66 | 67 | return 'g5Write' . Str::title($table->bo_table); 68 | })->toArray(); 69 | 70 | $g5Member = new G5Member; 71 | $admin = $g5Member->where('mb_id', '=', 'admin')->first(); 72 | $this->assertNotNull($admin->g5WriteFree); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/Unit/G5ModelFactoryTest.php: -------------------------------------------------------------------------------- 1 | assertTrue($G5WriteFree->count() > 0); 15 | } 16 | 17 | public function test_g5model_auto() 18 | { 19 | $notExistsModel = "\SilNex\GuLa\Gnu\G5WriteFree"; 20 | 21 | if (!class_exists($notExistsModel)) { 22 | $model = explode('\\', $notExistsModel); 23 | $table = Str::snake(end($model)); 24 | 25 | $G5WriteFree = new G5ModelFactory(['gula', $table]); 26 | 27 | $this->assertTrue($G5WriteFree->count() > 0); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /tests/Unit/G5RelationTest.php: -------------------------------------------------------------------------------- 1 | where('mb_id', '=', 'admin')->first(); 14 | 15 | $admin->g5Points()->first(); 16 | 17 | $this->assertTrue(true); 18 | } 19 | } --------------------------------------------------------------------------------