1.关联加入select指定字段
public function CustomerInfo()
{
return $this->belongsTo(CustomerInfo::class, 'customer_id', 'id')->select(['id', 'company_name', 'company_code', 'external_code', 'credit_total', 'customer_level', 'customer_state', 'goods_state']);
}
2. 闭包内select指定字段
ActiveJieSuan::with(['user' => function ($query) {$query->select('id','name');},
'active'=> function ($query) {
$query->select('id','name','start');
}
])
->paginate()->toArray();
3.简便写法
ActiveJieSuan::with(['user:id,name','active:id,name,start'])
->paginate()
->toArray();