💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
首先是模型配置 ``` //关联外表 public function group() { //第一个参数为目标model; 第二个参数为目标表内与本model关联的字段; 第三个字段为本model对外关联的字段 return $this->hasMany(UsersGroup::class, 'id', 'users_group_id'); } ``` 然后控制器查询 ``` $query = Users::select(); $query->with(['group' => function($query1){ $query1->select('id','group_name'); }]); ``` 返回的数据格式 ``` {id: 5, user_name: "赵倩", user_tel: "12345678901", create_time: "2022-05-11 08:35:12", level: 0,…} create_time: "2022-05-11 08:35:12" group: [{id: 2, group_name: "B组"}] id: 5 level: 0 user_name: "赵倩" user_tel: "12345678901" users_group_id: 2 ``` 列表输出渲染 ``` {field: 'users_group_id', title: '小组名称', minWidth: 120, align: "center", templet: function (data) { var html = ''; if(data.group[0].id==data.users_group_id){ html=data.group[0].group_name; } return html; }}, ```