where('id',$row->road_id)->find(); $row->roadtype = $road_info['roadtype']; }); self::beforeInsert(function ($row) { $road_info = Db::name('product_road')->where('id',$row->road_id)->find(); $row->roadtype = $road_info['roadtype']; }); } public function getRoadtypeList() { return ['1' => __('Roadtype 1'), '2' => __('Roadtype 2'), '3' => __('Roadtype 3')]; } public function getIsQudaoList() { return ['0' => __('Is_qudao 0'), '1' => __('Is_qudao 1')]; } public function getRoadtypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['roadtype']) ? $data['roadtype'] : ''); $list = $this->getRoadtypeList(); return isset($list[$value]) ? $list[$value] : ''; } public function getIsQudaoTextAttr($value, $data) { $value = $value ? $value : (isset($data['is_qudao']) ? $data['is_qudao'] : ''); $list = $this->getIsQudaoList(); return isset($list[$value]) ? $list[$value] : ''; } public function product() { return $this->belongsTo('Product', 'product_id', 'id', [], 'LEFT')->setEagerlyType(0); } public function road() { return $this->belongsTo('app\admin\model\Productroad', 'road_id', 'id', [], 'LEFT')->setEagerlyType(0); } }