where('id',$row->road_id)->find(); $row->chufatype = $road_info['roadtype']; }); self::beforeInsert(function ($row) { $road_info = Db::name('product_road')->where('id',$row->road_id)->find(); $row->chufatype = $road_info['roadtype']; }); } public function getChufatypeList() { return ['1' => __('Chufatype 1'), '2' => __('Chufatype 2')]; } public function getChufatypeTextAttr($value, $data) { $value = $value ? $value : (isset($data['chufatype']) ? $data['chufatype'] : ''); $list = $this->getChufatypeList(); 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); } }