<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 模型 * ## 定義 >數據庫中每一張表對應一個model,model繼承` app\common\model\BaseModel`,BaseModel 繼承think/model類 模型類名最好與數據表保持一直,或者相關有意義,比如表`eb_user`,模型名為`User` ### 定義表主鍵 ``` public static function tablePk(): string ``` ### 定義表名 ``` public static function tableName(): string ``` ### 查詢隱藏字段 ``` protected $hidden = [ 'add_ip', 'account', 'clean_time', 'last_ip', 'pwd']; ``` ### 自動寫入字段 ``` protected $insert = ['add_time', 'add_ip', 'last_time', 'last_ip']; ``` ### 修改器(配置自動寫入使用) ``` protected function setAddTimeAttr() { return time(); } protected function setAddIpAttr($value) { return app('request')->ip(); } ``` ### 獲取器 ``` public function getAddTimeAttr($value) { if(!empty($value)){ return date('Y-m-d H:i:s', (int)$value); } return ''; } ``` ### 一對一關聯 ``` //關聯分組 public function group() { return $this->hasOne(UserGroup::class,'id','group_id'); } ``` ### 一對多關聯 ``` //關聯標簽 public function label() { return $this->hasMany(UserLabelRelation::class,'uid','uid'); } ``` ### 搜索器 常用的搜索條件,創建模型類時請先定義好 ``` public function searchLikeAttr($query, $value) { $query->where('account|nickname|phone|real_name|uid', 'LIKE', "%$value%"); } ``` * ## 使用 User模型類只通過UserDao使用,模型不在其他模型中混用,或者其他Dao中使用 >dao和model一一對應,也只在對應的dao中使用 在dao中通過`setModel`關聯model ``` class UserDao extends BaseDao { protected function getModel(): string { return User::class; } } ``` 通過getModel獲取model實例 ``` $this->getModel() ``` 就可以配合關聯詞 `where`、`field`、`page`、`count`、`find`、`select`等 ``` return $this->getModel()->where([])->field('*')->with(['label'])->page(0, 10)->select()->toArray(); ``` 使用`$this->getSearch()`,傳入條件可以配合模型中創建的搜索器一起使用,是查詢條件更簡介
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看