介紹
think-repository
是為thinkphp 6.0.*
提供的儲存庫用於抽象資料層,使我們的應用程式更靈活地進行維護。
你懂的
ThinkPHP
>= thinkphp 6.0.*
安裝教學
Composer
composer require fanxd/think-repository dev-master
#使用說明
最好
在多應用程式
下使用
#指令
# #php think fanxd:repository Post
- 路由
- Route::resource('post', 'PostController');
- 可用的方法
- first($id) // 尋找單一記錄
- get() // 尋找記錄
- paginate() // 分頁查詢
- create($data) // 寫入資料
- save($data) // 儲存目前資料物件
- delete( $where) // 刪除記錄
update($where,$data) // 更新記錄find($id) // 尋找單一記錄如果不存在則拋出例外
findWhere($where,$columns = ['*']) // 指定AND查詢條件尋找單一記錄with([]) // 關聯查詢
#search( []) // 資料搜尋##order($order) // 排序
#尋找記錄
##$posts= $this->repository->get();
#分頁查詢
$posts=$this->repository-> ;paginate($limit);
按結果按id查找
$posts=$this->repository->find( $id);
$posts=$this->repository->first($id);
#載入模型關係
$posts=$this->repository->with(['state'])->find($id);
$posts=$this->repository->findByField('title', 'Hello');按結果依欄位名稱找出
#按結果由多個欄位找出$posts=$this->repository->findWhere([
'id' => 1], ['id', 'title]);
按結果在一個欄位中尋找多個值
$posts=$this->repository-> ;findWhereIn('id', [1,2,3,4,5]);
#透過排除一個欄位中的多個值,依結果找出
$posts=$this->repository->findWhereNotIn('id', [6,7,8,9,10]);
#寫入資料
$post = $this->repository->create($data);
##更新記錄$posts=$this->repository->update($where, $data);
##刪除記錄
$this->repository->delete($id)
#以多個欄位刪除儲存庫中的項目
$this->repository->deleteWhere([
'id' => 1, 'user_id' => 1])
transform檔案,可自行選擇是否啟用,主要功能對我來說就是美化介面讓我們更專業:)###
<?php namespace app\api\transform;use fanxd\repository\command\transform\Transform;class PostTransform extends Transform{ public function transform($items) { return [ 'id' => $items['id'], //... 'createTime' => $items['create_time'], 'updateTime' => $items['update_time'] ]; }}#### ##陸續增加更多的方法,如果你有好的想法可以告訴我,秒更!!!######相關推薦:###最新的10個thinkphp影片教學####### ##
以上是介紹一個好用的ThinkPHP Repository包的詳細內容。更多資訊請關注PHP中文網其他相關文章!

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver Mac版
視覺化網頁開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。