<?php /** * @qywx */ namespace app\admin\model\qywx; use app\admin\model\qywx\User; use app\common\model\BaseModel; class Gmsglog extends BaseModel { public function user() { return $this->hasOne(User::class, 'userid', 'sender'); } }
1.在當前的模型定義一個函數,用來關聯另一個模型
2.hasOne的第一個參數是被關聯的模型,第二個參數是外鍵,第三個參數是主鍵
$list = $this->model ->with(['user' => function ($query) { $query->field('token,userid,name'); }]) ->where($where) ->order($sort, $order) ->limit($offset, $limit) ->select();
1.with可以用於一個數組的方式,形成閉包處理字段或者where條件
思考:
1.需要在當前模型定義關聯類型
2.調用的時候直接with那個函數名稱
3.用數組閉包處理數據
項目介紹
基於ThinkPHP6.0和layui的快速開發的后台管理系統。
支持php8.0版本
技術交流QQ群:533738074 加群請備注來源:如gitee、github、官網等
。
站點地址
-
官方網站:http://ruan.scmls.cn
-
文檔地址:http://doc.scmls.cn
-
演示地址:http://mango.scmls.cn/admin(賬號:admin,密碼:123456。備注:只有查看信息的權限)