Download the PHP package thoth-pharaoh/base-model-repository without Composer
On this page you can find all versions of the php package thoth-pharaoh/base-model-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Please rate this library. Is it a good library?
Informations about the package base-model-repository
基礎抽象類別供專案使用
版本匹配
Laravel | package |
---|---|
8.X | 1.X |
9.X | 2.X |
AbstractBaseModel
使用方法
功能
- 自動載入 HasFactory Trait
- 自動設定 $guard = ['id']
- 自動序列化 DataTime 格式
Y-m-d H:i:s
AbstractBaseRepository
使用方法
取得所有資料
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$fields | 要搜尋的欄位 | array | ['name', 'type'] | ['*'] |
$eagerLoad | 預載入關聯 | array | ['post', 'post.comment'] | [] |
依搜尋條件取得資料(whereIn)
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$whereField | 搜尋條件欄位名稱 | string | 'name' | 'id' |
$whereValue | 搜尋條件資訊 | array | [1, 2, 3] | [] |
$field | 要搜尋的欄位 | array | ['id', 'name'] | ['*'] |
$eagerLoad | 預載入關聯 | array | ['post', 'post.comment'] | [] |
取得單筆資料
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$id | PK | 123 | ||
$eagerLoad | 預載入關聯 | array | ['post', 'post.comment'] | [] |
取得單筆資料(單一搜尋條件)
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$where | 搜尋條件資訊 | array | ['status', '=', 1] | |
$field | 要搜尋的欄位 | array | ['id', 'name'] | ['*'] |
$eagerLoad | 預載入關聯 | array | ['post', 'post.comment'] | [] |
完整範例
or
取得單筆資料 從寫入資料庫取得
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$id | PK | 123 |
取得單筆資料 從寫入資料庫取得 並加排他鎖
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$id | PK | 123 |
尋找在某個欄位有重複的數值及個數
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$field | 要搜尋的欄位 | string | 'member_id' | |
$where | 搜尋條件資訊 | array | ['status', '=', 1] | |
$havingCount | 取多少以上 | int | 5 | 1 |
完整範例
新增資料
參數 | 說明 | 類型 |
---|---|---|
$parametes | 新增資料陣列 | array |
完整範例
新增多筆資料
參數 | 說明 | 類型 |
---|---|---|
$parametes | 新增資料陣列 | array |
完整範例
更新單筆資料
參數 | 說明 | 類型 |
---|---|---|
$id | PK | |
$parametes | 更新資料陣列 | array |
完整範例
更新單筆資訊 根據指定欄位
參數 | 說明 | 類型 |
---|---|---|
$where | 搜尋條件資訊 | array |
$parametes | 更新資料陣列 | array |
完整範例
更新多筆資料
參數 | 說明 | 類型 | 預設 |
---|---|---|---|
$data | 更新條件資料 | array | |
$parameters | 更新資料陣列 | array | |
$field | 更新條件名稱 | string | 'id' |
完整範例
資料新增,存在則更新
參數 | 說明 | 類型 |
---|---|---|
$where | 搜尋條件資訊 | array |
$parametes | 更新資料陣列 | array |
完整範例
批次更新 or 新增資料
參數 | 說明 | 類型 |
---|---|---|
$parametes | 更新資料陣列 | array |
完整範例
一次更新多筆數據
參數 | 說明 | 類型 |
---|---|---|
$setField | 欲更新的欄位名稱 | string |
$caseField | 查詢依據欄位名稱 | string |
$setValue | 愈設定的數值 | array |
完整範例
增加數量
參數 | 說明 | 類型 |
---|---|---|
$where | 搜尋條件資訊 | array |
$field | 愈增加數量的欄位名稱 | string |
$num | 愈增加的數量 | int |
完整範例
減少數量
參數 | 說明 | 類型 |
---|---|---|
$where | 搜尋條件資訊 | array |
$field | 愈減少數量的欄位名稱 | string |
$num | 愈減少的數量 | int |
完整範例
依條件刪除資料
參數 | 說明 | 類型 |
---|---|---|
$where | 搜尋條件資訊 | array |
完整範例
AbstractBaseScope
使用方法
-
scope class 需繼承 AbstractBaseScope
-
初始化 $extensions
-
實作過濾條件方法 (名稱為$extensions中,元素名稱前面 + 'add', ex: 'Date' => 'addDate')
使用 $builder->macro 去建立方法內容 -
在 Model 中需加入該 global scope
- 在 Repository 中需註冊 scope
參數 | 說明 | 類型 | 範例 | 預設 |
---|---|---|---|---|
$scope | scope名稱 | AbstractBaseScope | OrderScope | |
$params | 過濾條件 | array | ['no' => 123] | |
$model | 欲使用的model (不給就使用原本$repository中的model) |
array | ['no' => 123] | $repository中的model |
完整範例
Helpers
使用方法
dd_sql
die and dump 整個 raw SQL 語句
範例
輸出結果
dump_sql
dump 整個 raw SQL 語句
範例
輸出結果
All versions of base-model-repository with dependencies
PHP Build Version
Package Version
The package thoth-pharaoh/base-model-repository contains the following files
Loading the files please wait ....